Skip to content
Snippets Groups Projects
Commit d20485ef authored by Rafael Ravedutti's avatar Rafael Ravedutti
Browse files

Fix CUDA device functions


Signed-off-by: default avatarRafael Ravedutti <rafaelravedutti@gmail.com>
parent 96d966b3
No related merge requests found
#include <cuda_runtime.h> #include <cuda_runtime.h>
#include <iostream> #include <iostream>
//--- //---
#include "pairs.hpp" #include "../pairs.hpp"
#pragma once #pragma once
#define CUDA_ASSERT(a) { pairs::cuda_assert((a), __LINE__, __FILE__); } #define CUDA_ASSERT(a) { pairs::cuda_assert((a), __FILE__, __LINE__); }
namespace pairs { namespace pairs {
inline void cuda_assert(cudaError_t err, const char *file, int line) { inline void cuda_assert(cudaError_t err, const char *file, int line) {
if(cuda != cudaSuccess) { if(err != cudaSuccess) {
std::cerr << file << ":" << line << ": " << cudaGetErrorString(err) << std::endl; std::cerr << file << ":" << line << ": " << cudaGetErrorString(err) << std::endl;
exit(-1); exit(-1);
} }
...@@ -29,11 +29,11 @@ __host__ __device__ void *device_realloc(void *ptr, size_t size) { ...@@ -29,11 +29,11 @@ __host__ __device__ void *device_realloc(void *ptr, size_t size) {
return new_ptr; return new_ptr;
} }
__host__ void copy_to_device(void *h_ptr, const void *d_ptr, size_t count) { __host__ void copy_to_device(const void *h_ptr, void *d_ptr, size_t count) {
CUDA_ASSERT(cudaMemcpy(d_ptr, h_ptr, count, cudaMemcpyHostToDevice)); CUDA_ASSERT(cudaMemcpy(d_ptr, h_ptr, count, cudaMemcpyHostToDevice));
} }
__host__ void copy_to_host(void *d_ptr, const void *h_ptr, size_t count) { __host__ void copy_to_host(const void *d_ptr, void *h_ptr, size_t count) {
CUDA_ASSERT(cudaMemcpy(h_ptr, d_ptr, count, cudaMemcpyDeviceToHost)); CUDA_ASSERT(cudaMemcpy(h_ptr, d_ptr, count, cudaMemcpyDeviceToHost));
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment