Commit e089d07f authored by Dmitry I. Lyakh's avatar Dmitry I. Lyakh

Implemented CREATE and DESTROY in TALSH node executor.

parent 7aaecaab
Pipeline #69282 passed with stage
in 4 minutes and 58 seconds
/** ExaTN: Tensor basic types and parameters
REVISION: 2019/06/05
REVISION: 2019/08/28
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -44,6 +44,15 @@ enum class TensorOpCode{
CONTRACT //tensor contraction
};
enum class TensorElementType{
REAL16,
REAL32,
REAL64,
COMPLEX16,
COMPLEX32,
COMPLEX64
};
} //namespace exatn
#endif //EXATN_NUMERICS_TENSOR_BASIC_HPP_
/** ExaTN::Numerics: Tensor operation: Creates a tensor
REVISION: 2019/08/15
REVISION: 2019/08/28
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -15,7 +15,7 @@ namespace exatn{
namespace numerics{
TensorOpCreate::TensorOpCreate():
TensorOperation(TensorOpCode::CREATE,1,0)
TensorOperation(TensorOpCode::CREATE,1,0), element_type_(TensorElementType::REAL64)
{
}
......@@ -35,6 +35,12 @@ std::unique_ptr<TensorOperation> TensorOpCreate::createNew()
return std::unique_ptr<TensorOperation>(new TensorOpCreate());
}
void TensorOpCreate::resetTensorElementType(TensorElementType element_type)
{
element_type_ = element_type;
return;
}
} //namespace numerics
} //namespace exatn
/** ExaTN::Numerics: Tensor operation: Creates a tensor
REVISION: 2019/08/15
REVISION: 2019/08/28
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -38,8 +38,18 @@ public:
/** Create a new polymorphic instance of this subclass. **/
static std::unique_ptr<TensorOperation> createNew();
/** Resets the tensor element type. **/
void resetTensorElementType(TensorElementType element_type);
/** Returns the tensor element type. **/
inline TensorElementType getTensorElementType() const {
return element_type_;
}
private:
TensorElementType element_type_; //tensor element type
};
} //namespace numerics
......
......@@ -5,11 +5,25 @@
namespace exatn {
namespace runtime {
bool TalshNodeExecutor::talsh_initialized_ = 0;
TensorOpExecHandle TalshNodeExecutor::execute(numerics::TensorOpCreate & op)
{
assert(op.isSet());
const auto & tensor = *(op.getTensorOperand(0));
//`Implement
const auto tensor_rank = tensor.getRank();
const auto tensor_hash = tensor.getTensorHash();
const auto & dim_extents = tensor.getDimExtents();
std::vector<int> extents(tensor_rank);
for(int i = 0; i < tensor_rank; ++i) extents[i] = static_cast<int>(dim_extents[i]);
auto data_kind = get_talsh_tensor_element_kind(op.getTensorElementType());
auto res = tensors_.emplace(std::make_pair(tensor_hash,
std::make_shared<talsh::Tensor>(extents,data_kind,talsh_tens_no_init)));
if(!res.second){
std::cout << "#ERROR(exatn::runtime::node_executor_talsh): Attempt to create the same tensor twice for tensor: " << std::endl;
tensor.printIt();
assert(false);
}
return op.getId();
}
......@@ -17,7 +31,14 @@ TensorOpExecHandle TalshNodeExecutor::execute(numerics::TensorOpCreate & op)
TensorOpExecHandle TalshNodeExecutor::execute(numerics::TensorOpDestroy & op)
{
assert(op.isSet());
//`Implement
const auto & tensor = *(op.getTensorOperand(0));
const auto tensor_hash = tensor.getTensorHash();
auto num_deleted = tensors_.erase(tensor_hash);
if(num_deleted != 1){
std::cout << "#ERROR(exatn::runtime::node_executor_talsh): Attempt to destroy non-existing tensor for tensor: " << std::endl;
tensor.printIt();
assert(false);
}
return op.getId();
}
......
/** ExaTN:: Tensor Runtime: Tensor graph node executor: Talsh
REVISION: 2019/08/26
REVISION: 2019/08/28
Copyright (C) 2018-2019 Dmitry Lyakh, Tiffany Mintz, Alex McCaskey
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle)
......@@ -44,8 +44,23 @@ protected:
std::unordered_map<numerics::TensorHashType,std::shared_ptr<talsh::Tensor>> tensors_;
/** Active execution handles associated with tensor operations currently executed by TAL-SH **/
std::unordered_map<TensorOpExecHandle,std::shared_ptr<talsh::TensorTask>> tasks_;
/** TAL-SH initialization status **/
static bool talsh_initialized_;
};
inline int get_talsh_tensor_element_kind(TensorElementType element_type)
{
int talsh_data_kind = NO_TYPE;
switch(element_type){
case TensorElementType::REAL32: talsh_data_kind = R4; break;
case TensorElementType::REAL64: talsh_data_kind = R8; break;
case TensorElementType::COMPLEX32: talsh_data_kind = C4; break;
case TensorElementType::COMPLEX64: talsh_data_kind = C8; break;
}
return talsh_data_kind;
}
} //namespace runtime
} //namespace exatn
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment