Skip to content

Commit

Permalink
Regards #590: Avoiding compilation warnings also in examples code
Browse files Browse the repository at this point in the history
  • Loading branch information
Eyal Rozenberg authored and eyalroz committed Feb 16, 2024
1 parent 2eb7a6e commit 882df66
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,19 @@ 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<double>(bytes_) * 1e-6 / static_cast<double>(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);
stream.enqueue.event(events.second);
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<struct sockaddr *>(&servaddr), SUN_LEN(&servaddr)) < 0) {
if (bind(server_fd, reinterpret_cast<struct sockaddr *>(&servaddr), (socklen_t) SUN_LEN(&servaddr)) < 0) {
perror("IPC failure: Binding socket failed");
return -1;
}
Expand Down Expand Up @@ -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<int>(i)));
}
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<struct sockaddr *>(&servaddr), SUN_LEN(&servaddr)) < 0) {
if (bind(server_fd, reinterpret_cast<struct sockaddr *>(&servaddr), (socklen_t) SUN_LEN(&servaddr)) < 0) {
perror("IPC failure: Binding socket failed");
return -1;
}
Expand Down Expand Up @@ -332,7 +332,7 @@ ipcSendShareableHandles(ipcHandle *handle, const std::vector<shared_pool_handle_
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], (int) i));
}
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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]) > (float) 1e-5) {
std::cerr << "Result verification failed at element " << i << "\n";
exit(EXIT_FAILURE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/other/jitify/jitify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace fs = std::experimental::filesystem;

template <typename T>
bool are_close(T in, T out) {
return fabs(in - out) <= 1e-5f * fabs(in);
return fabs(in - out) <= 1e-5 * fabs(in);
}

/**
Expand Down

0 comments on commit 882df66

Please sign in to comment.