Skip to content

Commit

Permalink
Merge pull request #19 from nlesc-recruit/header-only-cudawrapper
Browse files Browse the repository at this point in the history
Adapt example to new header only version of cudawrappers
matmanc authored Oct 3, 2023
2 parents 6a019a6 + 534305d commit af589ad
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "external/cudawrappers"]
path = external/cudawrappers
url = https://github.com/nlesc-recruit/cudawrappers
branch = main
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -14,10 +14,14 @@ set(CMAKE_BUILD_TYPE Release)
include(GNUInstallDirs)
list(APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})

set(CUDA_MIN_VERSION 10.0)
find_package(CUDAToolkit ${CUDA_MIN_VERSION} REQUIRED)

add_subdirectory(external/cudawrappers)

add_executable(vector_add_example vector_add.cpp)

target_embed_source(vector_add_example vector_add_kernel.cu)
target_link_libraries(vector_add_example PRIVATE cudawrappers::cu
cudawrappers::nvrtc)

8 changes: 6 additions & 2 deletions vector_add.cpp
Original file line number Diff line number Diff line change
@@ -31,16 +31,20 @@ void vector_add() {
my_stream.memcpyHtoDAsync(d_b, b, bytesize);

// compile kernel
extern const char _binary_vector_add_kernel_cu_start,
_binary_vector_add_kernel_cu_end;
const std::string kernel(&_binary_vector_add_kernel_cu_start,
&_binary_vector_add_kernel_cu_end);
std::vector<std::string> options = {};
nvrtc::Program program("vector_add_kernel.cu");
nvrtc::Program program(kernel, "vector_add_kernel.cu");
try {
program.compile(options);
} catch (nvrtc::Error &error) {
std::cerr << program.getLog();
throw;
}

cu::Module module = cu::Module((void *)program.getPTX().data());
cu::Module module(static_cast<const void *>(program.getPTX().data()));

cu::Function function(module, "vector_add");

0 comments on commit af589ad

Please sign in to comment.