diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b87d7b..9b20dbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,11 +2,10 @@ # GPUtils # ==================================================================== cmake_minimum_required(VERSION 3.20 FATAL_ERROR) - if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.29") cmake_policy(SET CMP0135 NEW) endif() - +# ---- # Set C++ version and SM architecture if (NOT DEFINED CPPVERSION) set(CPPVERSION 20) # A40: 20, Orin: 17 @@ -14,8 +13,7 @@ endif() if (NOT DEFINED SM_ARCH) set(SM_ARCH 86)# A40: 86, Orin: 87 endif() - - +# ---- project(GPUtils DESCRIPTION "Easy use of vectors and matrices on GPGPU devices." HOMEPAGE_URL "https://github.com/GPUEngineering/GPUtils" @@ -31,8 +29,8 @@ set(CMAKE_CUDA_FLAGS "-std=c++${CPPVERSION}") set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; "-std=c++${CPPVERSION}") enable_language(CUDA) # ---- -add_library(device_compiler_flags INTERFACE) -target_compile_features(device_compiler_flags INTERFACE cxx_std_${CPPVERSION}) +add_library(gputils_compiler_flags INTERFACE) +target_compile_features(gputils_compiler_flags INTERFACE cxx_std_${CPPVERSION}) set(CMAKE_CXX_EXTENSIONS OFF) # ---- add_library(developer_flags INTERFACE) @@ -45,30 +43,31 @@ target_compile_options(developer_flags # flags for CUDA builds $<$:${cuda_flags}> ) -target_link_libraries(device_compiler_flags INTERFACE $) +target_link_libraries(gputils_compiler_flags INTERFACE $) # ---- - - -# ==================================================================== -# comment out for release -# ==================================================================== -add_executable(main) -target_sources(main +add_executable(gputils_main) +target_sources(gputils_main PRIVATE main.cu ) -target_link_libraries(main +target_link_libraries(gputils_main PRIVATE - device_compiler_flags + gputils_compiler_flags cublas cusolver cudadevrt ) -target_include_directories(main +target_include_directories(gputils_main PRIVATE "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/include" ) # ---- -add_subdirectory(test) +if(NOT GPUTILS_BUILD_TEST) + set(GPUTILS_BUILD_TEST OFF) # Set to ON for local testing (or add `-DGPUTILS_BUILD_TEST=ON` to your CMake profile) +endif() +if (GPUTILS_BUILD_TEST) + add_subdirectory(test) +endif() +unset(GPUTILS_BUILD_TEST CACHE) # ---- diff --git a/ci/script.sh b/ci/script.sh index 6cf351d..102976f 100644 --- a/ci/script.sh +++ b/ci/script.sh @@ -7,7 +7,7 @@ tests() { cpp_version=17 # default sm_arch=86 # default hwInfoOrin=`lshw | grep Orin` || - if [ ! -z "${hwInfoOrin}" ]; then + if [ -n "${hwInfoOrin}" ]; then echo "Running on Orin"; sm_arch=87 cpp_version=17 @@ -22,7 +22,7 @@ tests() { # ------------------------------------ # -- create build files - cmake -DCPPVERSION=${cpp_version} -DSM_ARCH=${sm_arch} -S . -B ./build -Wno-dev + cmake -DCPPVERSION=${cpp_version} -DSM_ARCH=${sm_arch} -DGPUTILS_BUILD_TEST=ON -S . -B ./build -Wno-dev # -- build files in build folder cmake --build ./build @@ -34,7 +34,7 @@ tests() { # -- run compute sanitizer pushd ./build/test - mem=$(/usr/local/cuda/bin/compute-sanitizer --tool memcheck --leak-check=full ./device_test) + mem=$(/usr/local/cuda/bin/compute-sanitizer --tool memcheck --leak-check=full ./gputils_test) grep "0 errors" <<< "$mem" popd @@ -44,7 +44,7 @@ tests() { # -- create build files cd example - cmake -DCPPVERSION=${cpp_version} -DSM_ARCH=${sm_arch} -S . -B ./build -Wno-dev + cmake -DCPPVERSION=${cpp_version} -DSM_ARCH=${sm_arch} -S . -B ./build -Wno-dev # -- build files in build folder cmake --build ./build diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 4f84a78..1140d95 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -28,10 +28,8 @@ target_compile_options(example_developer_flags # flags for CUDA builds $<$:${cuda_flags}> ) -target_link_libraries(example_compiler_flags INTERFACE $ -) +target_link_libraries(example_compiler_flags INTERFACE $) # ---- -set(GPUTILS_BUILD_TESTING OFF) include(FetchContent) FetchContent_Declare( gputils diff --git a/include/tensor.cuh b/include/tensor.cuh index cee9dff..bca5706 100644 --- a/include/tensor.cuh +++ b/include/tensor.cuh @@ -608,7 +608,7 @@ data_t vectorFromTextFile(std::string path_to_file) { data_t dataStruct; std::ifstream file; file.open(path_to_file, std::ios::in); - if (!file.is_open()) { throw std::invalid_argument("the file you provided does not exist"); }; + if (!file.is_open()) { throw std::invalid_argument("[vectorFromTextFile] the file does not exist"); } std::string line; getline(file, line); dataStruct.numRows = atoi(line.c_str()); @@ -655,6 +655,7 @@ data_t vectorFromBinaryFile(std::string path_to_file) { /* Read from binary file */ std::ifstream inFile; inFile.open(path_to_file, std::ios::binary); + if (!inFile.is_open()) { throw std::invalid_argument("[vectorFromBinaryFile] the file does not exist"); } inFile.read(reinterpret_cast(&(dataStruct.numRows)), sizeof(uint64_t)); inFile.read(reinterpret_cast(&(dataStruct.numCols)), sizeof(uint64_t)); inFile.read(reinterpret_cast(&(dataStruct.numMats)), sizeof(uint64_t)); @@ -723,7 +724,7 @@ void DTensor::reshape(size_t newNumRows, size_t newNumCols, size_t newNumMats char errMessage[256]; sprintf(errMessage, "DTensor[%lu x %lu x %lu] with %lu elements cannot be reshaped into DTensor[%lu x %lu x %lu] (%lu elements)", - numRows(), numRows(), numMats(), numEl(), newNumRows, newNumCols, newNumMats, newNumElements); + numRows(), numCols(), numMats(), numEl(), newNumRows, newNumCols, newNumMats, newNumElements); throw std::invalid_argument(errMessage); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9259aa9..4abfa1c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,24 +9,23 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) # ---- enable_testing() -add_executable(device_test) - -target_sources(device_test # add files +add_executable(gputils_test) +target_sources(gputils_test # add files PRIVATE testTensor.cu ) -target_link_libraries(device_test +target_link_libraries(gputils_test PRIVATE - device_compiler_flags + gputils_compiler_flags cublas cusolver cudadevrt GTest::gtest_main) -target_include_directories(device_test +target_include_directories(gputils_test PRIVATE "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/include" ) include(GoogleTest) -gtest_discover_tests(device_test) +gtest_discover_tests(gputils_test) # ----