Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cuTensorNet plugin #56

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ 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_CUTENSORNET "Build the cuTensorNet plugin" OFF)


if(XACC_BUILD_ANNEALING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DANNEALING_ENABLED")
Expand Down Expand Up @@ -178,6 +180,17 @@ if(XACC_ENABLE_MPI)
endif()
endif()

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

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

if (XACC_DEPS_EXTERNAL)
find_package(Boost COMPONENTS graph)
find_package(cpr)
Expand Down
3 changes: 3 additions & 0 deletions quantum/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ add_subdirectory(algorithms)
add_subdirectory(xasm)
add_subdirectory(qpp)
add_subdirectory(staq)
if(XACC_BUILD_CUTENSORNET)
add_subdirectory(cutensornet)
endif()

if(XACC_REMOTE_ACCELERATORS)
add_subdirectory(ionq)
Expand Down
74 changes: 74 additions & 0 deletions quantum/plugins/cutensornet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
set(LIBRARY_NAME xacc-cutensornet)

file(GLOB SRC *.cpp)

usfunctiongetresourcesource(TARGET ${LIBRARY_NAME} OUT SRC)
usfunctiongeneratebundleinit(TARGET ${LIBRARY_NAME} OUT SRC)

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 .
${CUDA_TOOLKIT_ROOT}/include)

target_link_directories(${LIBRARY_NAME}
PRIVATE
${CUTENSOR_LIB}
${CUDA_TOOLKIT_ROOT}/lib64)

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

set(_bundle_name xacc_cutensornet)
set_target_properties(${LIBRARY_NAME}
PROPERTIES COMPILE_DEFINITIONS
US_BUNDLE_NAME=${_bundle_name}
US_BUNDLE_NAME
${_bundle_name})

usfunctionembedresources(TARGET
${LIBRARY_NAME}
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
FILES
manifest.json)

find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_compile_definitions(${LIBRARY_NAME} PUBLIC WITH_OPENMP_)
target_link_libraries(${LIBRARY_NAME} PUBLIC OpenMP::OpenMP_CXX)
endif()

if(APPLE)
set_target_properties(${LIBRARY_NAME}
PROPERTIES INSTALL_RPATH "@loader_path/../lib")
set_target_properties(${LIBRARY_NAME}
PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
else()
set_target_properties(${LIBRARY_NAME}
PROPERTIES INSTALL_RPATH "$ORIGIN/../lib")
set_target_properties(${LIBRARY_NAME} PROPERTIES
BUILD_RPATH "${CUTENSOR_ROOT}/lib/11")
set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-shared")
endif()

if(XACC_BUILD_TESTS)
add_subdirectory(tests)
endif()

message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/plugins)
Loading
Loading