From 94398e638285af4e306e07fb3df9444c25fb1981 Mon Sep 17 00:00:00 2001 From: Eyal Rozenberg Date: Thu, 15 Feb 2024 18:34:52 +0200 Subject: [PATCH] Regards #590: Avoiding compilation errors also in examples code --- .../bandwidthtest/bandwidthtest.cpp | 9 ++++++--- .../memMapIPCDrv/helper_multiprocess.cpp | 4 ++-- .../simpleDrvRuntimePTX/simpleDrvRuntimePTX.cpp | 2 +- .../streamOrderedAllocationIPC/helper_multiprocess.cpp | 4 ++-- .../vectorAdd_nvrtc/vectorAdd_nvrtc.cpp | 2 +- .../vectorAdd_ptx/vectorAdd_ptx.cpp | 2 +- examples/other/jitify/jitify.cpp | 2 +- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/modified_cuda_samples/bandwidthtest/bandwidthtest.cpp b/examples/modified_cuda_samples/bandwidthtest/bandwidthtest.cpp index 86f9abe3..bba9ac0f 100644 --- a/examples/modified_cuda_samples/bandwidthtest/bandwidthtest.cpp +++ b/examples/modified_cuda_samples/bandwidthtest/bandwidthtest.cpp @@ -58,8 +58,11 @@ void profileCopies(float *h_a, stream.enqueue.event(events.second); stream.synchronize(); - auto duration = cuda::event::time_elapsed_between(events.first, events.second); - std::cout << " Host to Device bandwidth (GB/s): " << (bytes * 1e-6 / duration.count()) << "\n"; + cuda::event::duration_t duration; + auto to_gb = [&duration](size_t bytes_) { + return static_cast(bytes_) * 1e-6 / static_cast(duration.count()); + }; + std::cout << " Host to Device bandwidth (GB/s): " << to_gb(bytes) << "\n"; stream.enqueue.event(events.first); stream.enqueue.copy(h_b, d, bytes); @@ -67,7 +70,7 @@ void profileCopies(float *h_a, stream.synchronize(); duration = cuda::event::time_elapsed_between(events); - std::cout << " Device to Host bandwidth (GB/s): " << (bytes * 1e-6 / duration.count()) << "\n"; + std::cout << " Device to Host bandwidth (GB/s): " << to_gb(bytes) << "\n"; bool are_equal = std::equal(h_a, h_a + nElements, h_b); if (not are_equal) { diff --git a/examples/modified_cuda_samples/memMapIPCDrv/helper_multiprocess.cpp b/examples/modified_cuda_samples/memMapIPCDrv/helper_multiprocess.cpp index 7517a1a2..ef8769b8 100644 --- a/examples/modified_cuda_samples/memMapIPCDrv/helper_multiprocess.cpp +++ b/examples/modified_cuda_samples/memMapIPCDrv/helper_multiprocess.cpp @@ -174,7 +174,7 @@ int ipcCreateSocket(ipcHandle *&handle, const char *name, strncpy(servaddr.sun_path, name, sizeof(servaddr.sun_path)); - if (bind(server_fd, reinterpret_cast(&servaddr), SUN_LEN(&servaddr)) < 0) { + if (bind(server_fd, reinterpret_cast(&servaddr), (socklen_t) SUN_LEN(&servaddr)) < 0) { perror("IPC failure: Binding socket failed"); return -1; } @@ -364,7 +364,7 @@ int ipcSendShareableHandles( for (std::size_t i = 0; i < shareableHandles.size(); i++) { for (std::size_t j = 0; j < processes.size(); j++) { checkIpcErrors( - ipcSendShareableHandle(handle, shareableHandles, processes[j], i)); + ipcSendShareableHandle(handle, shareableHandles, processes[j], static_cast(i))); } } return 0; diff --git a/examples/modified_cuda_samples/simpleDrvRuntimePTX/simpleDrvRuntimePTX.cpp b/examples/modified_cuda_samples/simpleDrvRuntimePTX/simpleDrvRuntimePTX.cpp index 25151826..ae7924c6 100644 --- a/examples/modified_cuda_samples/simpleDrvRuntimePTX/simpleDrvRuntimePTX.cpp +++ b/examples/modified_cuda_samples/simpleDrvRuntimePTX/simpleDrvRuntimePTX.cpp @@ -168,7 +168,7 @@ int main(int argc, char** argv) stream.synchronize(); for (int i = 0; i < N; ++i) { - if (std::fabs(h_A.get()[i] + h_B.get()[i] - h_C.get()[i]) > 1e-5) { + if (std::fabs(h_A.get()[i] + h_B.get()[i] - h_C.get()[i]) > 1e-5f) { std::cerr << "Result verification failed at element " << i << "\n"; exit(EXIT_FAILURE); } diff --git a/examples/modified_cuda_samples/streamOrderedAllocationIPC/helper_multiprocess.cpp b/examples/modified_cuda_samples/streamOrderedAllocationIPC/helper_multiprocess.cpp index 26bf1262..e5b50264 100644 --- a/examples/modified_cuda_samples/streamOrderedAllocationIPC/helper_multiprocess.cpp +++ b/examples/modified_cuda_samples/streamOrderedAllocationIPC/helper_multiprocess.cpp @@ -174,7 +174,7 @@ int ipcCreateSocket(ipcHandle *&handle, const char *name, strncpy(servaddr.sun_path, name, sizeof(servaddr.sun_path)); - if (bind(server_fd, reinterpret_cast(&servaddr), SUN_LEN(&servaddr)) < 0) { + if (bind(server_fd, reinterpret_cast(&servaddr), (socklen_t) SUN_LEN(&servaddr)) < 0) { perror("IPC failure: Binding socket failed"); return -1; } @@ -332,7 +332,7 @@ ipcSendShareableHandles(ipcHandle *handle, const std::vector 1e-5) { + if (std::fabs(h_A.get()[i] + h_B.get()[i] - h_C.get()[i]) > (float) 1e-5) { std::cerr << "Result verification failed at element " << i << "\n"; exit(EXIT_FAILURE); } diff --git a/examples/modified_cuda_samples/vectorAdd_ptx/vectorAdd_ptx.cpp b/examples/modified_cuda_samples/vectorAdd_ptx/vectorAdd_ptx.cpp index 7c23f0b0..2ff3cf5d 100644 --- a/examples/modified_cuda_samples/vectorAdd_ptx/vectorAdd_ptx.cpp +++ b/examples/modified_cuda_samples/vectorAdd_ptx/vectorAdd_ptx.cpp @@ -133,7 +133,7 @@ int main(void) // Verify that the result vector is correct for (int i = 0; i < numElements; ++i) { - if (std::fabs(h_A.get()[i] + h_B.get()[i] - h_C.get()[i]) > 1e-5) { + if (std::fabs(h_A.get()[i] + h_B.get()[i] - h_C.get()[i]) > 1e-5f) { std::cerr << "Result verification failed at element " << i << "\n"; exit(EXIT_FAILURE); } diff --git a/examples/other/jitify/jitify.cpp b/examples/other/jitify/jitify.cpp index 380fa56a..31c7d9de 100644 --- a/examples/other/jitify/jitify.cpp +++ b/examples/other/jitify/jitify.cpp @@ -60,7 +60,7 @@ namespace fs = std::experimental::filesystem; template bool are_close(T in, T out) { - return fabs(in - out) <= 1e-5f * fabs(in); + return fabs(in - out) <= 1e-5 * fabs(in); } /**