-
Notifications
You must be signed in to change notification settings - Fork 15
/
talsh_task.cpp
132 lines (103 loc) · 3.15 KB
/
talsh_task.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/** ExaTensor::TAL-SH: Device-unified user-level C++ API implementation.
REVISION: 2020/06/19
Copyright (C) 2014-2022 Dmitry I. Lyakh (Liakh)
Copyright (C) 2014-2022 Oak Ridge National Laboratory (UT-Battelle)
LICENSE: BSD 3-Clause
-------------------------------------------------------------------
**/
#include "talsh_task.hpp"
#include "talshxx.hpp"
#include <iostream>
#include <cassert>
namespace talsh{
TensorTask::TensorTask():
num_tensors_(0)
{
int errc = talshTaskClean(&talsh_task_);
assert(errc == TALSH_SUCCESS);
}
TensorTask::~TensorTask()
{
this->wait();
int errc = talshTaskDestruct(&talsh_task_);
assert(errc == TALSH_SUCCESS);
}
bool TensorTask::isEmpty()
{
return (talshTaskIsEmpty(&talsh_task_) == YEP);
}
void TensorTask::clean()
{
int status = talshTaskStatus(&talsh_task_);
if(status != TALSH_TASK_ERROR && status != TALSH_TASK_EMPTY && status != TALSH_TASK_COMPLETED) this->wait();
for(int i = 0; i < num_tensors_; ++i){
Tensor * tensor = used_tensors_[i];
if(tensor->getWriteTask() == this) tensor->resetWriteTask();
}
num_tensors_ = 0;
int errc = talshTaskDestruct(&talsh_task_);
assert(errc == TALSH_SUCCESS);
return;
}
bool TensorTask::wait()
{
int stats = TALSH_TASK_COMPLETED;
if(talshTaskIsEmpty(&talsh_task_) != YEP){
int errc;
int completed = talshTaskComplete(&talsh_task_,&stats,&errc);
if(errc != TALSH_SUCCESS) std::cout << "#ERROR(TAL-SH:TensorTask.wait): Task completion check failed: Error " << errc << std::endl; //debug
assert(errc == TALSH_SUCCESS);
if(completed != YEP){
errc = talshTaskWait(&talsh_task_,&stats);
if(errc != TALSH_SUCCESS) std::cout << "#ERROR(TAL-SH:TensorTask.wait): Task completion wait failed: Error " << errc << std::endl; //debug
assert(errc == TALSH_SUCCESS);
}
if(stats != TALSH_TASK_COMPLETED){ //debug
std::cout << "#ERROR(TAL-SH:TensorTask.wait): Task completed with error: Status " << stats << std::endl;
talshTaskPrint(&talsh_task_);
assert(stats == TALSH_TASK_COMPLETED);
}
}
this->clean();
return (stats == TALSH_TASK_COMPLETED);
}
bool TensorTask::test(int * status)
{
bool res = true;
if(talshTaskIsEmpty(&talsh_task_) != YEP){
int errc;
res = (talshTaskComplete(&talsh_task_,status,&errc) == YEP);
if(errc != TALSH_SUCCESS) std::cout << "#ERROR(TAL-SH:TensorTask.test): Task completion check failed: Error " << errc << std::endl; //debug
assert(errc == TALSH_SUCCESS);
}else{ //empty task: Completed = TRUE
*status = TALSH_TASK_EMPTY;
}
if(res) this->clean();
return res;
}
int TensorTask::getExecutionDevice(int * device_kind)
{
return talshTaskDevId(&talsh_task_,device_kind);
}
unsigned int TensorTask::getNumTensorArguments() const
{
return num_tensors_;
}
const Tensor * TensorTask::getTensorArgument(unsigned int arg_num) const
{
if(arg_num < num_tensors_) return used_tensors_[arg_num];
return nullptr;
}
const talshTensArg_t * TensorTask::getTensorArgumentImages(int * num_arguments)
{
return talshTaskTensArgs(&talsh_task_,num_arguments);
}
int TensorTask::getTensorArgumentCoherence()
{
return talshTaskArgCoherence(&talsh_task_);
}
talsh_task_t * TensorTask::getTalshTaskPtr()
{
return &talsh_task_;
}
} //namespace talsh