1 #ifndef VIENNACL_BACKEND_CUDA_HPP_
2 #define VIENNACL_BACKEND_CUDA_HPP_
32 #include <cuda_runtime.h>
34 #define VIENNACL_CUDA_ERROR_CHECK(err) detail::cuda_error_check (err, __FILE__, __LINE__)
60 if(cudaSuccess != error_code)
62 std::cerr << file <<
"(" << line <<
"): " <<
": CUDA Runtime API error " << error_code <<
": " << cudaGetErrorString( error_code ) << std::endl;
89 void * dev_ptr = NULL;
100 cudaMemcpy(new_handle.
get(), host_ptr, size_in_bytes, cudaMemcpyHostToDevice);
120 assert( (dst_buffer.
get() != NULL) &&
bool(
"Memory not initialized!"));
121 assert( (src_buffer.
get() != NULL) &&
bool(
"Memory not initialized!"));
123 cudaMemcpy(reinterpret_cast<void *>(dst_buffer.
get() + dst_offset),
124 reinterpret_cast<void *>(src_buffer.
get() + src_offset),
126 cudaMemcpyDeviceToDevice);
144 assert( (dst_buffer.
get() != NULL) &&
bool(
"Memory not initialized!"));
147 cudaMemcpyAsync(reinterpret_cast<char *>(dst_buffer.
get()) + dst_offset,
148 reinterpret_cast<const char *>(ptr),
150 cudaMemcpyHostToDevice);
152 cudaMemcpy(reinterpret_cast<char *>(dst_buffer.
get()) + dst_offset,
153 reinterpret_cast<const char *>(ptr),
155 cudaMemcpyHostToDevice);
173 assert( (src_buffer.
get() != NULL) &&
bool(
"Memory not initialized!"));
176 cudaMemcpyAsync(reinterpret_cast<char *>(ptr),
177 reinterpret_cast<char *>(src_buffer.
get()) + src_offset,
179 cudaMemcpyDeviceToHost);
181 cudaMemcpy(reinterpret_cast<char *>(ptr),
182 reinterpret_cast<char *>(src_buffer.
get()) + src_offset,
184 cudaMemcpyDeviceToHost);
void cuda_error_check(cudaError error_code, const char *file, const int line)
Definition: cuda.hpp:58
std::size_t vcl_size_t
Definition: forwards.h:58
void memory_write(handle_type &dst_buffer, vcl_size_t dst_offset, vcl_size_t bytes_to_copy, const void *ptr, bool async=false)
Writes data from main RAM identified by 'ptr' to the CUDA buffer identified by 'dst_buffer'.
Definition: cuda.hpp:138
void memory_copy(handle_type const &src_buffer, handle_type &dst_buffer, vcl_size_t src_offset, vcl_size_t dst_offset, vcl_size_t bytes_to_copy)
Copies 'bytes_to_copy' bytes from address 'src_buffer + src_offset' on the CUDA device to memory star...
Definition: cuda.hpp:114
viennacl::tools::shared_ptr< char > handle_type
Definition: cuda.hpp:42
Implementation of a shared pointer class (cf. std::shared_ptr, boost::shared_ptr). Will be used until C++11 is widely available.
#define VIENNACL_CUDA_ERROR_CHECK(err)
Definition: cuda.hpp:34
Functor for deleting a CUDA handle. Used within the smart pointer class.
Definition: cuda.hpp:70
handle_type memory_create(vcl_size_t size_in_bytes, const void *host_ptr=NULL)
Creates an array of the specified size on the CUDA device. If the second argument is provided...
Definition: cuda.hpp:87
void memory_read(handle_type const &src_buffer, vcl_size_t src_offset, vcl_size_t bytes_to_copy, void *ptr, bool async=false)
Reads data from a CUDA buffer back to main RAM.
Definition: cuda.hpp:167
void operator()(U *p) const
Definition: cuda.hpp:72