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
35 changes: 17 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
# 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
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"
Expand All @@ -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)
Expand All @@ -45,30 +43,31 @@ target_compile_options(developer_flags
# flags for CUDA builds
$<$<COMPILE_LANGUAGE:CUDA>:${cuda_flags}>
)
target_link_libraries(device_compiler_flags INTERFACE $<BUILD_INTERFACE:developer_flags>)
target_link_libraries(gputils_compiler_flags INTERFACE $<BUILD_INTERFACE:developer_flags>)
# ----


# ====================================================================
# 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)
# ----
8 changes: 4 additions & 4 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ target_compile_options(example_developer_flags
# flags for CUDA builds
$<$<COMPILE_LANGUAGE:CUDA>:${cuda_flags}>
)
target_link_libraries(example_compiler_flags INTERFACE $<BUILD_INTERFACE:example_developer_flags>
)
target_link_libraries(example_compiler_flags INTERFACE $<BUILD_INTERFACE:example_developer_flags>)
# ----
set(GPUTILS_BUILD_TESTING OFF)
include(FetchContent)
FetchContent_Declare(
gputils
Expand Down
5 changes: 3 additions & 2 deletions include/tensor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ data_t<T> vectorFromTextFile(std::string path_to_file) {
data_t<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());
Expand Down Expand Up @@ -655,6 +655,7 @@ data_t<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<char *>(&(dataStruct.numRows)), sizeof(uint64_t));
inFile.read(reinterpret_cast<char *>(&(dataStruct.numCols)), sizeof(uint64_t));
inFile.read(reinterpret_cast<char *>(&(dataStruct.numMats)), sizeof(uint64_t));
Expand Down Expand Up @@ -723,7 +724,7 @@ void DTensor<T>::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);
}

Expand Down
13 changes: 6 additions & 7 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
# ----