Commit 79dc9123 authored by Dmitry I. Lyakh's avatar Dmitry I. Lyakh

[INTERMEDIATE] Fixing reduced tensor shaping in the TAL-SH node executor ...

parent 36216423
/** ExaTN:: Tensor Runtime: Tensor graph node executor: Talsh
REVISION: 2020/06/25
REVISION: 2020/06/26
Copyright (C) 2018-2020 Dmitry Lyakh, Tiffany Mintz, Alex McCaskey
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle)
......@@ -101,6 +101,64 @@ TalshNodeExecutor::~TalshNodeExecutor()
}
TalshNodeExecutor::TensorImpl::TensorImpl(const std::vector<DimExtent> & full_extents,
const std::vector<int> & reduced_extents,
int data_kind):
talsh_tensor(std::make_shared<talsh::Tensor>(reduced_extents,data_kind,talsh_tens_no_init)),
stored_shape(nullptr), full_shape_is_on(false)
{
auto errc = tensShape_create(&stored_shape); assert(errc == TALSH_SUCCESS);
int full_rank = full_extents.size();
int dims[full_rank];
for(int i = 0; i < full_rank; ++i){
if(full_extents[i] > static_cast<DimExtent>(std::numeric_limits<int>::max())){
std::cout << "#FATAL(exatn::runtime::TalshNodeExecutor): CREATE: Tensor dimension extent exceeds max int: "
<< full_extents[i] << std::endl << std::flush;
assert(false);
}
dims[i] = full_extents[i];
}
errc = tensShape_construct(stored_shape,NOPE,full_rank,dims); assert(errc == TALSH_SUCCESS);
}
TalshNodeExecutor::TensorImpl::~TensorImpl()
{
if(stored_shape != nullptr){
auto errc = tensShape_destroy(stored_shape); assert(errc == TALSH_SUCCESS);
stored_shape = nullptr;
}
}
void TalshNodeExecutor::TensorImpl::resetTensorShapeToFull()
{
if(!full_shape_is_on){
auto * talsh_tens = talsh_tensor->getTalshTensorPtr();
talsh_tens_shape_t * current_shape = talsh_tens->shape_p;
assert(current_shape != nullptr && stored_shape != nullptr);
talsh_tens->shape_p = stored_shape;
stored_shape = current_shape;
full_shape_is_on = true;
}
return;
}
void TalshNodeExecutor::TensorImpl::resetTensorShapeToReduced()
{
if(full_shape_is_on){
auto * talsh_tens = talsh_tensor->getTalshTensorPtr();
talsh_tens_shape_t * current_shape = talsh_tens->shape_p;
assert(current_shape != nullptr && stored_shape != nullptr);
talsh_tens->shape_p = stored_shape;
stored_shape = current_shape;
full_shape_is_on = false;
}
return;
}
int TalshNodeExecutor::execute(numerics::TensorOpCreate & op,
TensorOpExecHandle * exec_handle)
{
......@@ -112,17 +170,15 @@ int TalshNodeExecutor::execute(numerics::TensorOpCreate & op,
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]);
#if 0
auto iter = extents.begin();
while(iter != extents.end()){
if(*iter > 1){
++iter;
}else{
iter = extents.erase(iter);
iter = extents.erase(iter); //removing extent-1 dimensions
}
}
tensor_rank = extents.size();
#endif
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)));
......
/** ExaTN:: Tensor Runtime: Tensor graph node executor: Talsh
REVISION: 2020/06/22
REVISION: 2020/06/26
Copyright (C) 2018-2020 Dmitry Lyakh, Tiffany Mintz, Alex McCaskey
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle)
......@@ -98,12 +98,33 @@ public:
protected:
struct TensorImpl{
//TAL-SH tensor with reduced shape (all extent-1 tensor dimensions removed):
std::shared_ptr<talsh::Tensor> talsh_tensor;
//The original full tensor shape:
talsh_tens_shape_t * stored_shape;
//Flag which tensor shape is currently in use by the TAL-SH tensor:
bool full_shape_is_on;
//Lifecycle:
TensorImpl(const std::vector<DimExtent> & full_extents, //full tensor shape
const std::vector<int> & reduced_extents, //reduced tensor shape
int data_kind); //TAL-SH tensor data kind
TensorImpl(const TensorImpl &) = delete;
TensorImpl & operator=(const TensorImpl &) = delete;
TensorImpl(TensorImpl &&) noexcept = default;
TensorImpl & operator=(TensorImpl &&) noexcept = default;
~TensorImpl();
//Resets TAL-SH tensor shape between full and reduced, depending on the operation needs:
void resetTensorShapeToFull();
void resetTensorShapeToReduced();
};
struct CachedAttr{
double last_used; //time stamp of last usage
double last_used; //time stamp of last usage of the cached tensor image
};
/** Determines whether a given TAL-SH tensor is currently participating
in an active tensor operation or tensor prefetch. **/
in an active tensor operation, tensor prefetch or tensor eviction. **/
bool tensorIsCurrentlyInUse(const talsh::Tensor * talsh_tens) const;
/** Maps generic exatn::numerics::Tensor to its TAL-SH implementation talsh::Tensor **/
......
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