Skip to content
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
20 changes: 15 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
*.e
*.o
*.so
# Python
__pycache__
.python-version
/build*
.cache/

# CMake
CMakeUserPresets.json

# Visual Studio Code
.vscode/

# this project
build/
Testing/

# need to be cleaned up
.cache/
*.swp
*.swo
dev_test
*.e
*.o
*.so
108 changes: 97 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,106 @@ FILE(APPEND "${CMAKE_BINARY_DIR}/vinfo.tmp" "${CYTNX_VARIANT_INFO}" "")
# #####################################################################
# ## COMMAND LINE OPTIONS
# #####################################################################
option(BACKEND_TORCH "Build Cytnx with pytorch backend (requires pytorch)" OFF)

# # the following are only referenced when BACKEND_TORCH=OFF
option(USE_CUDA "Build using Nvidia CUDA for GPU library" OFF)
option(BUILD_PYTHON "Build Python wrapper" ON)
option(USE_MKL "Build using MKL" ON)
option(BUILD_DOC "Build API docuemntation" OFF)
option(USE_HPTT "Build Cytnx with HPTT" OFF)
# -----------------------------------------------------------------------------
# :Function: require_dependent_variable
#
# :Description:
# Conditionally creates or validates a cache variable based on a set of
# dependency conditions.
#
# The dependency conditions are provided in the *depends* parameter as a
# semicolon-separated list. The cache variable is required only when all
# these conditions evaluate to true.
#
# :Parameters:
# - **variable**: The name of the variable to set.
# - **default**: The default value for the variable.
# - **type**: The cache type (e.g., STRING, PATH) for the variable.
# - **help**: A descriptive help message for the variable.
# - **depends**: A semicolon-separated list of dependency conditions.
# The variable is required only if all conditions are met.
#
# :Behavior:
# - Evaluates each dependency condition; if any condition evaluates to false,
# will not update the variable.
# - If all conditions are met and the variable is not already defined, the
# variable is set to the provided default value in the cache using the
# specified type and help message.
# - If the variable’s value is empty, a fatal error is raised.
#
# :Examples:
#
# .. code-block:: cmake
#
# require_dependent_variable(
# PACKAGE_INCLUDE_DIRS
# "$ENV{PACKAGE_INCLUDE_DIRS}"
# PATH
# "Path to the include directory of the package."
# "USE_A AND (USE_B OR USE_C);USE_D"
# )
#
# In this example, if "USE_A AND (USE_B OR USE_C);USE_D" is true, then
# PACKAGE_INCLUDE_DIRS must be defined and non-empty. Otherwise, a fatal error
# is raised.
# -----------------------------------------------------------------------------
function(require_dependent_variable variable default type help depends)
# Evaluate each dependency condition; if any condition is false, exit early.
# This is copied from the source code of `cmake_dependent_option` function.
set(IS_NOT_AVAILABLE 0)
foreach(d ${depends})
cmake_language(EVAL CODE "
if (${d})
else()
set(IS_NOT_AVAILABLE 1)
endif()"
)
endforeach()
if(IS_NOT_AVAILABLE)
return()
endif()

if(NOT DEFINED ${variable})
set(${variable} "${default}" CACHE ${type} "${help}")
endif()

if("${${variable}}" STREQUAL "")
message(FATAL_ERROR "\
Error: Cache variable '${variable}' is required under dependency conditions \
(${depends}) but its value is empty.
${help}
")
endif()
endfunction()

include(CMakeDependentOption)

set(CMAKE_INSTALL_PREFIX "/usr/local/cytnx" CACHE PATH "the destination path for installation")
option(BUILD_PYTHON "Build Python API. Require Python and pybind11 installed." ON)
option(BACKEND_TORCH "Use PyTorch as a backend container for tensors." OFF)
cmake_dependent_option(USE_MKL "Use MKL as a BLAS provider otherwise use OpenBLAS." OFF "NOT BACKEND_TORCH" OFF)
cmake_dependent_option(USE_HPTT "Use HPTT library to accelrate tensor transpose." OFF "NOT BACKEND_TORCH" OFF)
cmake_dependent_option(HPTT_ENABLE_FINE_TUNE "Enable fine tune HPTT for the native hardware." OFF "USE_HPTT" OFF)
# TODO: use variable instead of option to handle HPTT variant.
cmake_dependent_option(HPTT_ENABLE_ARM "HPTT variant" OFF "USE_HPTT;NOT HPTT_ENABLE_AVX; NOT HPTT_ENABLE_IBM" OFF)
cmake_dependent_option(HPTT_ENABLE_AVX "HPTT variant" OFF "USE_HPTT;NOT HPTT_ENABLE_ARM; NOT HPTT_ENABLE_IBM" OFF)
cmake_dependent_option(HPTT_ENABLE_IBM "HPTT variant" OFF "USE_HPTT;NOT HPTT_ENABLE_ARM; NOT HPTT_ENABLE_AVX" OFF)
cmake_dependent_option(USE_CUDA "Enable CUDA support." OFF "NOT BACKEND_TORCH" OFF)
cmake_dependent_option(USE_CUTT "Use CUTT library to accelrate tensor transpose." OFF "USE_CUDA" OFF)
cmake_dependent_option(CUTT_ENABLE_FINE_TUNE "Enable CUTT fine tune for the native hardware." OFF "USE_CUTT" OFF)
cmake_dependent_option(USE_CUTENSOR "Enable cuTENSOR." OFF "USE_CUDA" OFF)
require_dependent_variable(CUTENSOR_ROOT "$ENV{CUTENSOR_ROOT}" PATH
"Please provide CUTENSOR_ROOT in the environment variables.
CUTENSOR_ROOT is the path to the folder of cuTENSOR." "USE_CUTENSOR")
cmake_dependent_option(USE_CUQUANTUM "Enable cuQuantum." OFF "USE_CUDA" OFF)
require_dependent_variable(CUQUANTUM_ROOT "$ENV{CUQUANTUM_ROOT}" PATH
"Please provide CUQUANTUM_ROOT in the environment variables.
CUQUANTUM_ROOT is the path to the folder of cuQuantum." "USE_CUQUANTUM")
option(RUN_TESTS "Run Cytnx tests" OFF)
option(RUN_BENCHMARKS "Run Cytnx benchmarks" OFF)
option(USE_CUTT "Build Cytnx with CUTT" OFF)
option(USE_CUTENSOR "Build Cytnx with CuTensor (requires CUDA)" ON)
option(USE_CUQUANTUM "Build Cytnx with CUQuantum (requires CUDA)" ON)

option(USE_DEBUG "Build in debug more and enable address sanitizer" OFF)
option(BUILD_DOC "Build API docuemntation" OFF)
option(DEV_MODE "Build testing dev_test.cpp with cytnx" OFF)

# #####################################################################
Expand Down
170 changes: 170 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "openblas-cpu",
"description": "OpenBLAS as the BLAS vendor with CPU-only support.",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/build/${presetName}/libcytnx",
"CMAKE_EXPORT_COMPILE_COMMANDS": "OFF",
"USE_MKL": "OFF",
"BUILD_PYTHON": "ON",
"BACKEND_TORCH": "OFF",
"USE_HPTT": "ON",
"HPTT_ENABLE_FINE_TUNE": "ON",
"USE_CUDA": "OFF",
"RUN_TESTS": "OFF",
"RUN_BENCHMARKS": "OFF",
"USE_DEBUG": "OFF",
"BUILD_DOC": "OFF",
"DEV_MODE": "OFF"
}
},
{
"name": "mkl",
"hidden": true,
"description": "A base preset overriding OpenBLAS variables with MKL variables.",
"cacheVariables": {
"USE_MKL": "ON"
}
},
{
"name": "mkl-cpu",
"displayName": "mkl-cpu",
"description": "Intel MKL as the BLAS vendor with CPU-only support.",
"inherits": ["mkl", "default"]
},
{
"name": "openblas-cuda",
"displayName": "openblas-cuda",
"description": "OpenBLAS as the BLAS vendor with CUDA support.",
"inherits": "default",
"cacheVariables": {
"USE_CUDA": "ON",
"USE_CUTT": "ON",
"CUTT_ENABLE_FINE_TUNE": "ON",
"USE_CUTENSOR": "ON",
"USE_CUQUANTUM": "ON"
}
},
{
"name": "mkl-cuda",
"displayName": "mkl-cuda",
"description": "Intel MKL as the BLAS vendor with CUDA support.",
"inherits": ["mkl", "openblas-cuda"]
},
{
"name": "debug",
"hidden": true,
"description": "A base preset overriding release variables with debug variables.",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"USE_DEBUG": "ON",
"RUN_TESTS": "ON",
"RUN_BENCHMARKS": "OFF",
"BUILD_DOC": "OFF",
"DEV_MODE": "OFF"
}
},
{
"name": "debug-openblas-cpu",
"displayName": "debug-openblas-cpu",
"description": "Debug build: OpenBLAS as the BLAS vendor with CPU-only support.",
"inherits": ["debug", "default"]
},
{
"name": "debug-mkl-cpu",
"displayName": "debug-mkl-cpu",
"description": "Debug build: Intel MKL as the BLAS vendor with CPU-only support.",
"inherits": ["debug", "mkl-cpu"]
},
{
"name": "debug-openblas-cuda",
"displayName": "debug-openblas-cuda",
"description": "Debug build: OpenBLAS as the BLAS vendor with CUDA support.",
"inherits": ["debug", "openblas-cuda"]
},
{
"name": "debug-mkl-cuda",
"displayName": "debug-mkl-cuda",
"description": "Debug build: Intel MKL as the BLAS vendor with CUDA support.",
"inherits": ["debug", "mkl-cuda"]
}
],
"buildPresets": [
{
"name": "default",
"displayName": "openblas-cpu",
"description": "Build using OpenBLAS with CPU-only support.",
"configurePreset": "default",
"targets": ["all", "install"],
"jobs": 8
},
{
"name": "openblas-cuda",
"description": "Build using OpenBLAS with CUDA support.",
"configurePreset": "openblas-cuda",
"inherits": "default"
},
{
"name": "mkl-cuda",
"description": "Build using Intel MKL with CUDA support.",
"configurePreset": "mkl-cuda",
"inherits": "default"
},
{
"name": "debug-openblas-cpu",
"description": "Debug build using OpenBLAS with CPU-only support.",
"configurePreset": "debug",
"inherits": "default"
},
{
"name": "debug-mkl-cpu",
"description": "Debug build using Intel MKL with CPU-only support.",
"configurePreset": "debug-mkl-cpu",
"inherits": "default"
},
{
"name": "debug-openblas-cuda",
"description": "Debug build using OpenBLAS with CUDA support.",
"configurePreset": "debug-openblas-cuda",
"inherits": "default"
},
{
"name": "debug-mkl-cuda",
"description": "Debug build using Intel MKL with CUDA support.",
"configurePreset": "debug-mkl-cuda",
"inherits": "default"
}
],
"testPresets": [
{
"name": "default",
"displayName": "cpu-only",
"description": "Run tests for CPU-only builds.",
"configurePreset": "debug",
"output": {
"outputOnFailure": true,
"verbosity": "verbose"
},
"execution": {
"jobs": 8
}
},
{
"name": "cpu-and-cuda",
"description": "Run tests for builds with CUDA support.",
"configurePreset": "debug-openblas-cuda",
"inherits": "default"
}
]
}
Loading
Loading