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

[SofaCUDA] Check that the CUDA standard is the one specified in CMake #5167

Closed
Closed
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
5 changes: 3 additions & 2 deletions applications/plugins/SofaCUDA/SofaCUDANvccFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ cuda_select_nvcc_arch_flags(CUDA_ARCH_FLAGS ${CUDA_ARCH_LIST})

set(SOFA_ADDITIONAL_CUDA_NVCC_FLAGS "-Xcompiler")
if(NOT WIN32)
set(SOFA_ADDITIONAL_CUDA_NVCC_FLAGS "${SOFA_ADDITIONAL_CUDA_NVCC_FLAGS} -fPIC")
set(SOFA_ADDITIONAL_CUDA_NVCC_FLAGS "${SOFA_ADDITIONAL_CUDA_NVCC_FLAGS};-fPIC")
endif()
set(SOFA_ADDITIONAL_CUDA_NVCC_FLAGS "${SOFA_ADDITIONAL_CUDA_NVCC_FLAGS};-std=c++17")

list(APPEND CUDA_NVCC_FLAGS ${CUDA_ARCH_FLAGS} ${SOFA_ADDITIONAL_CUDA_NVCC_FLAGS})

Expand All @@ -21,4 +22,4 @@ if (WIN32)
set(CUDA_NVCC_FLAGS_DEBUG "--compiler-options /MDd")
endif (WIN32)

message(STATUS "SofaCUDA: nvcc flags: ${CUDA_NVCC_FLAGS}")
message(STATUS "SofaCUDA: nvcc flags: ${CUDA_NVCC_FLAGS}")
3 changes: 3 additions & 0 deletions applications/plugins/SofaCUDA/examples/empty.scn
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Node name="root">
<RequiredPlugin name="SofaCUDA"/>
</Node>
30 changes: 30 additions & 0 deletions applications/plugins/SofaCUDA/sofa/gpu/cuda/mycuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ cudaDeviceProp mycudaDeviceProp;


#if defined(__cplusplus)

#define STRINGIFY(x) #x
#define _STR(x) STRINGIFY(x)
SOFA_PRAGMA_MESSAGE("__cplusplus value: " _STR(__cplusplus))

namespace sofa
{
namespace gpu
Expand Down Expand Up @@ -193,9 +198,28 @@ bool cudaCheck(cudaError_t err, const char* src="?")
bool cudaInitCalled = false;
int deviceCount = 0;

#ifdef SOFA_WITH_DEVTOOLS
__global__ void print_cuda_standard()
{
/**
* 199711L = C++98
* 201103L = C++11
* 201402L = C++14
* 201703L = C++17
* 202002L = C++20
*/
printf("CUDA Standard: %ld\n", __cplusplus);
}
#endif

int mycudaInit(int device)
{
if (cudaInitCalled) return 1;

#if defined(__cplusplus)
mycudaPrintf("C++ standard = %ld", __cplusplus);
#endif

cudaInitCalled = true;
const cudaError_t getDeviceCountError = cudaGetDeviceCount(&deviceCount);
if (getDeviceCountError != cudaSuccess)
Expand Down Expand Up @@ -257,6 +281,12 @@ int mycudaInit(int device)
#if defined(SOFA_GPU_CUBLAS) && !defined(SOFA_GPU_CUBLAS_V2)
cublasInit();
#endif

#ifdef SOFA_WITH_DEVTOOLS
print_cuda_standard<<<1, 1>>>();
cudaCheck(cudaDeviceSynchronize());
#endif

return 1;
}

Expand Down
Loading