Commit 680564c0 authored by Dmitry I. Lyakh's avatar Dmitry I. Lyakh

Implemented TensorRuntime test, does not work, need to debug.

parent 37f65774
Pipeline #69707 passed with stage
in 4 minutes and 56 seconds
#include "tensor_runtime.hpp"
#include "exatn_service.hpp"
#include <iostream>
namespace exatn {
namespace runtime {
......@@ -9,6 +11,7 @@ TensorRuntime::TensorRuntime(const std::string & graph_executor_name, const std:
{
graph_executor_ = exatn::getService<TensorGraphExecutor>(graph_executor_name);
graph_executor_->resetNodeExecutor(exatn::getService<TensorNodeExecutor>(node_executor_name));
launchExecutionThread();
}
......@@ -16,7 +19,9 @@ TensorRuntime::~TensorRuntime()
{
if(alive_.load()){
alive_.store(false); //signal for the execution thread to finish
std::cout << "#DEBUG(exatn::runtime::TensorRuntime)[MAIN_THREAD]: Waiting Execution Thread ... ";
exec_thread_.join(); //wait until the execution thread has finished
std::cout << "Joined" << std::endl;
}
}
......@@ -25,7 +30,9 @@ void TensorRuntime::launchExecutionThread()
{
if(!(alive_.load())){
alive_.store(true);
std::cout << "#DEBUG(exatn::runtime::TensorRuntime)[MAIN_THREAD]: Launching Execution Thread ... ";
exec_thread_ = std::thread(&TensorRuntime::executionThreadWorkflow,this);
std::cout << "Done" << std::endl;
}
return; //only the main thread returns to the client
}
......
......@@ -69,9 +69,6 @@ public:
TensorRuntime & operator=(TensorRuntime &&) noexcept = delete;
~TensorRuntime();
/** Launches the execution thread which will be executing DAGs on the fly. **/
void launchExecutionThread();
/** Opens a new scope represented by a new execution graph (DAG). **/
void openScope(const std::string & scope_name);
......@@ -107,6 +104,8 @@ public:
TensorDenseBlock getTensorData(const Tensor & tensor);
protected:
/** Launches the execution thread which will be executing DAGs on the fly. **/
void launchExecutionThread();
/** The execution thread lives here **/
void executionThreadWorkflow();
......
......@@ -15,7 +15,57 @@
TEST(TensorRuntimeTester, checkSimple) {
//`Implement tests here
using exatn::numerics::Tensor;
using exatn::numerics::TensorShape;
using exatn::TensorOpCode;
using exatn::numerics::TensorOperation;
using exatn::numerics::TensorOpFactory;
auto & op_factory = *(TensorOpFactory::get()); //tensor operation factory
//Declare ExaTN tensors:
auto tensor0 = std::make_shared<Tensor>("tensor0",TensorShape{16,32,16,32});
auto tensor1 = std::make_shared<Tensor>("tensor1",TensorShape{16,16,64,64});
auto tensor2 = std::make_shared<Tensor>("tensor2",TensorShape{32,64,64,32});
//Create tensor operations for actual tensor construction:
std::shared_ptr<TensorOperation> create_tensor0 = op_factory.createTensorOp(TensorOpCode::CREATE);
create_tensor0->setTensorOperand(tensor0);
std::shared_ptr<TensorOperation> create_tensor1 = op_factory.createTensorOp(TensorOpCode::CREATE);
create_tensor1->setTensorOperand(tensor1);
std::shared_ptr<TensorOperation> create_tensor2 = op_factory.createTensorOp(TensorOpCode::CREATE);
create_tensor2->setTensorOperand(tensor2);
//Create tensor operation for contracting tensors:
std::shared_ptr<TensorOperation> contract_tensors = op_factory.createTensorOp(TensorOpCode::CONTRACT);
contract_tensors->setTensorOperand(tensor0);
contract_tensors->setTensorOperand(tensor1);
contract_tensors->setTensorOperand(tensor2);
contract_tensors->setScalar(0,std::complex<double>{0.5,0.0});
contract_tensors->setIndexPattern("D(a,b,c,d)+=L(c,a,k,l)*R(d,l,k,b)");
//Create tensor operations for tensor destruction:
std::shared_ptr<TensorOperation> destroy_tensor2 = op_factory.createTensorOp(TensorOpCode::DESTROY);
destroy_tensor2->setTensorOperand(tensor2);
std::shared_ptr<TensorOperation> destroy_tensor1 = op_factory.createTensorOp(TensorOpCode::DESTROY);
destroy_tensor1->setTensorOperand(tensor1);
std::shared_ptr<TensorOperation> destroy_tensor0 = op_factory.createTensorOp(TensorOpCode::DESTROY);
destroy_tensor0->setTensorOperand(tensor0);
#if 0
//Execute all tensor operations via numerical server:
exatn::numericalServer->submit(create_tensor0);
exatn::numericalServer->submit(create_tensor1);
exatn::numericalServer->submit(create_tensor2);
exatn::numericalServer->submit(contract_tensors);
exatn::numericalServer->submit(destroy_tensor2);
exatn::numericalServer->submit(destroy_tensor1);
exatn::numericalServer->submit(destroy_tensor0);
#endif
}
......
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