Commit 33322ac3 authored by Dmitry I. Lyakh's avatar Dmitry I. Lyakh
Browse files

Added TensorNetworkQueue to cuQuantum backend.

parent c6afe52e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ target_include_directories(${LIBRARY_NAME}
  graph_executors/lazy
  ../graph
  ${CMAKE_SOURCE_DIR}/src/exatn
  cuquantum
)

set(_bundle_name exatn_runtime_executor)
+2 −2
Original line number Diff line number Diff line
@@ -19,12 +19,12 @@ target_include_directories(${LIBRARY_NAME}
target_link_libraries(${LIBRARY_NAME} PUBLIC exatn-numerics)

if(CUQUANTUM)
  target_include_directories(${LIBRARY_NAME} PUBLIC ${CUQUANTUM_PATH}/include)
  target_include_directories(${LIBRARY_NAME} PRIVATE ${CUQUANTUM_PATH}/include)
  target_link_libraries(${LIBRARY_NAME} PRIVATE ${CUQUANTUM_PATH}/lib64/libcutensornet.so)
endif()

if(CUTENSOR AND NOT CUTENSOR_PATH STREQUAL ".")
  target_include_directories(${LIBRARY_NAME} PUBLIC ${CUTENSOR_PATH}/include)
  target_include_directories(${LIBRARY_NAME} PRIVATE ${CUTENSOR_PATH}/include)
  target_link_libraries(${LIBRARY_NAME} PRIVATE ${CUTENSOR_PATH}/lib/11/libcutensor.so)
endif()

+13 −2
Original line number Diff line number Diff line
/** ExaTN: Tensor Runtime: Tensor network executor: NVIDIA cuQuantum
REVISION: 2021/12/14
REVISION: 2021/12/21

Copyright (C) 2018-2021 Dmitry Lyakh
Copyright (C) 2018-2021 Oak Ridge National Laboratory (UT-Battelle)
@@ -10,13 +10,24 @@ Rationale:

#ifdef CUQUANTUM

#include "cuquantum_executor.hpp"
#include <cutensornet.h>
#include <cutensor.h>
#include <cuda_runtime.h>

#include <vector>

#include <iostream>

#include "cuquantum_executor.hpp"

namespace exatn {
namespace runtime {

struct TensorNetworkReq {
 std::shared_ptr<numerics::TensorNetwork> network;
};


CuQuantumExecutor::CuQuantumExecutor()
{
 const size_t version = cutensornetGetVersion();
+13 −14
Original line number Diff line number Diff line
/** ExaTN: Tensor Runtime: Tensor network executor: NVIDIA cuQuantum
REVISION: 2021/12/20
REVISION: 2021/12/21

Copyright (C) 2018-2021 Dmitry Lyakh
Copyright (C) 2018-2021 Oak Ridge National Laboratory (UT-Battelle)
@@ -16,34 +16,31 @@ Rationale:
#ifndef EXATN_RUNTIME_CUQUANTUM_EXECUTOR_HPP_
#define EXATN_RUNTIME_CUQUANTUM_EXECUTOR_HPP_

#include "tensor_network.hpp"
#include "tensor_operation.hpp"

#include <cutensornet.h>
#include <cutensor.h>
#include <cuda_runtime.h>

#include <unordered_map>
#include <vector>
#include <cassert>

#include "errors.hpp"
#include "tensor_network_queue.hpp"

namespace exatn {
namespace runtime {

struct TensorNetworkReq;


class CuQuantumExecutor {

public:

 CuQuantumExecutor();

 CuQuantumExecutor(const CuQuantumExecutor &) = delete;
 CuQuantumExecutor & operator=(CuQuantumExecutor &) = delete;
 CuQuantumExecutor(CuQuantumExecutor &&) noexcept = delete;
 CuQuantumExecutor & operator=(CuQuantumExecutor &&) noexcept = delete;
 virtual ~CuQuantumExecutor() = default;

 int execute(numerics::TensorNetwork & network,
 int execute(std::shared_ptr<numerics::TensorNetwork> network,
             TensorOpExecHandle * exec_handle);

 bool sync(TensorOpExecHandle op_handle,
 bool sync(TensorOpExecHandle exec_handle,
           int * error_code,
           bool wait = true);

@@ -51,6 +48,8 @@ public:

protected:

 /** Currently processed tensor networks **/
 std::unordered_map<TensorOpExecHandle,std::unique_ptr<TensorNetworkReq>> active_networks_;
};

} //namespace runtime
+54 −0
Original line number Diff line number Diff line
/** ExaTN: Tensor Runtime: Tensor network executor: Execution queue
REVISION: 2021/12/21

Copyright (C) 2018-2021 Dmitry Lyakh
Copyright (C) 2018-2021 Oak Ridge National Laboratory (UT-Battelle)

Rationale:
 - ExaTN graph executor may accept whole tensor networks for execution
   via the optional cuQuantum backend in which case the graph executor
   will delegate execution of whole tensor networks to CuQuantumExecutor.

**/

#ifndef EXATN_RUNTIME_TENSOR_NETWORK_QUEUE_HPP_
#define EXATN_RUNTIME_TENSOR_NETWORK_QUEUE_HPP_

#include "tensor_network.hpp"
#include "tensor_operation.hpp"

#include <list>
#include <memory>
#include <atomic>
#include <mutex>

#include "errors.hpp"

namespace exatn {
namespace runtime {

class TensorNetworkQueue {

public:

 TensorNetworkQueue() = default;
 TensorNetworkQueue(const TensorNetworkQueue &) = delete;
 TensorNetworkQueue & operator=(const TensorNetworkQueue &) = delete;
 TensorNetworkQueue(TensorNetworkQueue &&) noexcept = delete;
 TensorNetworkQueue & operator=(TensorNetworkQueue &&) noexcept = delete;
 ~TensorNetworkQueue() = default;

 inline void lock(){queue_lock_.lock();}
 inline void unlock(){queue_lock_.unlock();}

protected:

 std::list<std::pair<std::shared_ptr<numerics::TensorNetwork>,
                     TensorOpExecHandle>> networks_;
 std::mutex queue_lock_;
};

} //namespace runtime
} //namespace exatn

#endif //EXATN_RUNTIME_TENSOR_NETWORK_QUEUE_HPP_
Loading