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

Fixed TAL-SH initialization/shutdown in TalshNodeExecuctor.

parent cba9492b
/** ExaTN: Tensor basic types and parameters
REVISION: 2019/08/28
REVISION: 2019/09/01
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -45,6 +45,7 @@ enum class TensorOpCode{
};
enum class TensorElementType{
VOID,
REAL16,
REAL32,
REAL64,
......
......@@ -47,6 +47,7 @@ bool ExatensorNodeExecutor::sync(TensorOpExecHandle op_handle,
int * error_code,
bool wait)
{
*error_code = 0;
//`Implement
return false;
}
......
/** ExaTN:: Tensor Runtime: Tensor graph node executor: Exatensor
REVISION: 2019/08/30
REVISION: 2019/09/01
Copyright (C) 2018-2019 Dmitry Lyakh, Tiffany Mintz, Alex McCaskey
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle)
......@@ -20,6 +20,13 @@ class ExatensorNodeExecutor : public TensorNodeExecutor {
public:
ExatensorNodeExecutor() = default;
ExatensorNodeExecutor(const ExatensorNodeExecutor &) = delete;
ExatensorNodeExecutor & operator=(const ExatensorNodeExecutor &) = delete;
ExatensorNodeExecutor(ExatensorNodeExecutor &&) noexcept = delete;
ExatensorNodeExecutor & operator=(ExatensorNodeExecutor &&) noexcept = delete;
~ExatensorNodeExecutor() = default;
int execute(numerics::TensorOpCreate & op,
TensorOpExecHandle * exec_handle) override;
int execute(numerics::TensorOpDestroy & op,
......
#include "node_executor_talsh.hpp"
#include <mutex>
#include <cassert>
namespace exatn {
namespace runtime {
bool TalshNodeExecutor::talsh_initialized_ = false;
int TalshNodeExecutor::talsh_initialized_ = 0;
inline void check_initialize_talsh()
std::mutex talsh_init_lock;
TalshNodeExecutor::TalshNodeExecutor()
{
if(!TalshNodeExecutor::talsh_initialized_){
auto error_code = talsh::initialize();
if(error_code == TALSH_SUCCESS) TalshNodeExecutor::talsh_initialized_ = true;
talsh_init_lock.lock();
if(talsh_initialized_ == 0){
std::size_t host_buffer_size = 1024*1024*1024; //`Get max Host memory from OS
auto error_code = talsh::initialize(&host_buffer_size);
if(error_code == TALSH_SUCCESS){
std::cout << "#DEBUG(exatn::runtime::TalshNodeExecutor): TAL-SH initialized with Host buffer size of " <<
host_buffer_size << " Bytes" << std::endl;
}else{
std::cout << "#FATAL(exatn::runtime::TalshNodeExecutor): Unable to initialize TAL-SH!" << std::endl;
assert(false);
}
}
++talsh_initialized_;
talsh_init_lock.unlock();
}
TalshNodeExecutor::~TalshNodeExecutor()
{
talsh_init_lock.lock();
--talsh_initialized_;
if(talsh_initialized_ == 0){
auto error_code = talsh::shutdown();
if(error_code == TALSH_SUCCESS){
std::cout << "#DEBUG(exatn::runtime::TalshNodeExecutor): TAL-SH shut down" << std::endl;
}else{
std::cout << "#FATAL(exatn::runtime::TalshNodeExecutor): Unable to shut down TAL-SH!" << std::endl;
assert(false);
}
}
return;
talsh_init_lock.unlock();
}
......@@ -21,7 +51,6 @@ int TalshNodeExecutor::execute(numerics::TensorOpCreate & op,
TensorOpExecHandle * exec_handle)
{
assert(op.isSet());
check_initialize_talsh();
const auto & tensor = *(op.getTensorOperand(0));
const auto tensor_rank = tensor.getRank();
const auto tensor_hash = tensor.getTensorHash();
......@@ -45,7 +74,6 @@ int TalshNodeExecutor::execute(numerics::TensorOpDestroy & op,
TensorOpExecHandle * exec_handle)
{
assert(op.isSet());
check_initialize_talsh();
const auto & tensor = *(op.getTensorOperand(0));
const auto tensor_hash = tensor.getTensorHash();
auto num_deleted = tensors_.erase(tensor_hash);
......@@ -63,7 +91,6 @@ int TalshNodeExecutor::execute(numerics::TensorOpTransform & op,
TensorOpExecHandle * exec_handle)
{
assert(op.isSet());
check_initialize_talsh();
//`Implement
*exec_handle = op.getId();
return 0;
......@@ -74,7 +101,6 @@ int TalshNodeExecutor::execute(numerics::TensorOpAdd & op,
TensorOpExecHandle * exec_handle)
{
assert(op.isSet());
check_initialize_talsh();
const auto & tensor0 = *(op.getTensorOperand(0));
const auto tensor0_hash = tensor0.getTensorHash();
auto tens0_pos = tensors_.find(tensor0_hash);
......@@ -117,7 +143,6 @@ int TalshNodeExecutor::execute(numerics::TensorOpContract & op,
TensorOpExecHandle * exec_handle)
{
assert(op.isSet());
check_initialize_talsh();
const auto & tensor0 = *(op.getTensorOperand(0));
const auto tensor0_hash = tensor0.getTensorHash();
auto tens0_pos = tensors_.find(tensor0_hash);
......@@ -170,7 +195,6 @@ bool TalshNodeExecutor::sync(TensorOpExecHandle op_handle,
int * error_code,
bool wait)
{
check_initialize_talsh();
*error_code = 0;
bool synced = true;
auto iter = tasks_.find(op_handle);
......
/** ExaTN:: Tensor Runtime: Tensor graph node executor: Talsh
REVISION: 2019/08/30
REVISION: 2019/09/01
Copyright (C) 2018-2019 Dmitry Lyakh, Tiffany Mintz, Alex McCaskey
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle)
......@@ -25,6 +25,13 @@ class TalshNodeExecutor : public TensorNodeExecutor {
public:
TalshNodeExecutor();
TalshNodeExecutor(const TalshNodeExecutor &) = delete;
TalshNodeExecutor & operator=(const TalshNodeExecutor &) = delete;
TalshNodeExecutor(TalshNodeExecutor &&) noexcept = delete;
TalshNodeExecutor & operator=(TalshNodeExecutor &&) noexcept = delete;
~TalshNodeExecutor();
int execute(numerics::TensorOpCreate & op,
TensorOpExecHandle * exec_handle) override;
int execute(numerics::TensorOpDestroy & op,
......@@ -44,28 +51,39 @@ public:
const std::string description() const override {return "TALSH tensor graph node executor";}
std::shared_ptr<TensorNodeExecutor> clone() override {return std::make_shared<TalshNodeExecutor>();}
friend void check_initialize_talsh();
protected:
/** Maps generic exatn::numerics::Tensor to its TAL-SH implementation talsh::Tensor **/
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_;
static int talsh_initialized_; //number of active TAL-SH node executors
};
/** ExaTN tensor element kind --> TAL-SH tensor element kind converter **/
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;
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;
}
/** TAL-SH tensor element kind --> ExaTN tensor element kind converter **/
inline TensorElementType get_exatn_tensor_element_kind(int element_type)
{
switch(element_type){
case R4: return TensorElementType::REAL32;
case R8: return TensorElementType::REAL64;
case C4: return TensorElementType::COMPLEX32;
case C8: return TensorElementType::COMPLEX64;
}
return TensorElementType::VOID;
}
} //namespace runtime
......
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