Skip to content

Commit

Permalink
Cleaned up cmake
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Claudino <claudinodc@ornl.gov>
  • Loading branch information
danclaudino committed Dec 9, 2024
1 parent b85d1e6 commit e8cc93d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 65 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ option(XACC_BUILD_ATOS "Build the Atos QLM plugin" OFF)
option(XACC_BUILD_QFACTOR "Build the QFactor plugin" OFF)
option(XACC_BUILD_QSEARCH "Build the QSearch plugin" OFF)
option(XACC_BUILD_QRACK "Build the Qrack plugin" OFF)
option(XACC_BUILD_MPS "Build the cuTensorNet plugin" OFF)
option(XACC_BUILD_CUTENSORNET "Build the cuTensorNet plugin" OFF)


if(XACC_BUILD_ANNEALING)
Expand Down Expand Up @@ -180,14 +180,14 @@ if(XACC_ENABLE_MPI)
endif()
endif()

if(XACC_BUILD_MPS)
if(XACC_BUILD_CUTENSORNET)
enable_language(CUDA)
find_package(CUDA)
find_package(CUDAToolkit REQUIRED)

if(CUDA_FOUND)
message(STATUS "${Green}Found CUDA.${ColorReset}")
if(CUDAToolkit_FOUND)
message(STATUS "${Green}Found CUDA Toolkit.${ColorReset}")
else()
message(STATUS "${BoldYellow}CUDA not found.${ColorReset}")
message(STATUS "${BoldYellow}CUDA Toolkit not found.${ColorReset}")
endif()
endif()

Expand Down
48 changes: 21 additions & 27 deletions quantum/plugins/cutensornet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,33 @@ file(GLOB SRC *.cpp)
usfunctiongetresourcesource(TARGET ${LIBRARY_NAME} OUT SRC)
usfunctiongeneratebundleinit(TARGET ${LIBRARY_NAME} OUT SRC)

set(CMAKE_CUDA_ARCHITECTURES 75)

add_library(${LIBRARY_NAME} SHARED ${SRC})
if(CMAKE_MINOR_VERSION GREATER_EQUAL 24)
set_property(TARGET ${LIBRARY_NAME} PROPERTY CUDA_ARCHITECTURES native)
else()
if(CUDA_ARCH STREQUAL "")
message(SEND_ERROR "Your version of cmake does not set CUDA ARCHITECTURES automatically. Pass it with the -DCUDA_ARCH flag.")
else()
set(CMAKE_CUDA_ARCHITECTURES ${CUDA_ARCH})
endif()
endif()

target_include_directories(${LIBRARY_NAME}
PUBLIC .
${CUQUANTUM_ROOT}/include
${CUTENSOR_ROOT}/include)

find_library(CUTENSORNET_LIB cutensornet HINTS ${CUQUANTUM_ROOT}/lib)
# First try to locate libcutensor.so.2
# Find the primary cutensor library
find_library(CUTENSOR_LIB cutensor HINTS ${CUTENSOR_ROOT}/lib/11)
PUBLIC .
${CUDA_TOOLKIT_ROOT}/include)

# Try to locate the versioned libcutensor.so.2, if available
find_library(CUTENSOR_LIB2 libcutensor.so.2 HINTS ${CUTENSOR_ROOT}/lib/11)

if(NOT CUTENSOR_LIB)
message(FATAL_ERROR "Could not find libcutensor")
endif()

if(NOT CUTENSOR_LIB2)
message(FATAL_ERROR "Could not find libcutensor2")
endif()
target_link_directories(${LIBRARY_NAME}
PRIVATE
${CUTENSOR_LIB}
${CUDA_TOOLKIT_ROOT}/lib64)

target_link_libraries(${LIBRARY_NAME}
PUBLIC xacc
xacc-quantum-gate
PRIVATE
${CUTENSORNET_LIB}
${CUTENSOR_LIB}
${CUTENSOR_LIB2}
cudart)
PUBLIC
xacc
xacc-quantum-gate
PRIVATE
cutensornet
cudart)

set(_bundle_name xacc_cutensornet)
set_target_properties(${LIBRARY_NAME}
Expand Down
2 changes: 1 addition & 1 deletion quantum/plugins/cutensornet/CuTensorNetAccelerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void CuTensorNetAccelerator::initialize(const HeterogeneousMap &params) {
if (!cutnHandle) {
HANDLE_CUTN_ERROR(cutensornetCreate(&cutnHandle));
}
std::cout << "Initialized cuTensorNet library on GPU 0\n";
xacc::info("Initialized cuTensorNet library on GPU 0");

if (params.keyExists<int>("bond-dimension")) {
bondDimension = params.get<int>("bond-dimension");
Expand Down
5 changes: 1 addition & 4 deletions quantum/plugins/cutensornet/CuTensorNetAccelerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
*******************************************************************************/
#pragma once
#include "xacc.hpp"
#include "CuTensorNetVisitor.hpp"
#include "CuTensorNetHandles.hpp"
#include "PauliOperator.hpp"

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

namespace xacc {
namespace quantum {

Expand Down
24 changes: 24 additions & 0 deletions quantum/plugins/cutensornet/CuTensorNetHandles.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once
#include <cuda_runtime.h>
#include <cutensornet.h>

#define HANDLE_CUDA_ERROR(x) \
{ \
const auto err = x; \
if (err != cudaSuccess) { \
printf("CUDA error %s in line %d\n", cudaGetErrorString(err), __LINE__); \
fflush(stdout); \
std::abort(); \
} \
};

#define HANDLE_CUTN_ERROR(x) \
{ \
const auto err = x; \
if (err != CUTENSORNET_STATUS_SUCCESS) { \
printf("cuTensorNet error %s in line %d\n", \
cutensornetGetErrorString(err), __LINE__); \
fflush(stdout); \
std::abort(); \
} \
};
26 changes: 1 addition & 25 deletions quantum/plugins/cutensornet/CuTensorNetVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,8 @@
#include "AllGateVisitor.hpp"
#include <complex>
#include <vector>
#include <iostream>
#include <cmath>

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

#define HANDLE_CUDA_ERROR(x) \
{ \
const auto err = x; \
if (err != cudaSuccess) { \
printf("CUDA error %s in line %d\n", cudaGetErrorString(err), __LINE__); \
fflush(stdout); \
std::abort(); \
} \
};

#define HANDLE_CUTN_ERROR(x) \
{ \
const auto err = x; \
if (err != CUTENSORNET_STATUS_SUCCESS) { \
printf("cuTensorNet error %s in line %d\n", \
cutensornetGetErrorString(err), __LINE__); \
fflush(stdout); \
std::abort(); \
} \
};
#include "CuTensorNetHandles.hpp"

using namespace xacc;
using namespace xacc::quantum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEST(CuTensorNetAcceleratorTester, testDeuteron)
xacc::set_verbose(true);
std::shared_ptr<xacc::quantum::PauliOperator> observable = std::make_shared<
xacc::quantum::
PauliOperator>("X0 X1 + Z0");
PauliOperator>("X0 X1");
auto accelerator = xacc::getAccelerator("cutensornet", {{"bond-dimension", 2}, {"observable", observable}});
//auto xasmCompiler = xacc::getCompiler("xasm");
/*
Expand Down Expand Up @@ -65,7 +65,7 @@ xacc::set_verbose(true);
auto program = ir->getComposite("ansatz");

int c = 0;
auto angles = xacc::linspace(-xacc::constants::pi, xacc::constants::pi, 21);
auto angles = xacc::linspace(-xacc::constants::pi, xacc::constants::pi, 20);
for (auto &a : angles) {
auto buffer = xacc::qalloc(2);
auto evaled = program->operator()({a});
Expand Down

0 comments on commit e8cc93d

Please sign in to comment.