Created
July 11, 2013 11:55
-
-
Save pfac/5974813 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef ___MSC__CUDA__ARRAY_HPP___ | |
#define ___MSC__CUDA__ARRAY_HPP___ | |
// project headers | |
#include <msc/cuda/error> | |
namespace CUDA { | |
template<typename T> | |
class array { | |
size_t data_size; | |
T * device_data; | |
public: | |
array (const T * const host_data, const ulong count) { | |
data_size = sizeof(T) * count; | |
HANDLE_ERROR( cudaMalloc(&device_data, data_size) ); | |
HANDLE_ERROR( cudaMemcpy(device_data, host_data, data_size, cudaMemcpyHostToDevice) ); | |
} | |
~array () { | |
HANDLE_ERROR( cudaFree(device_data) ); | |
} | |
// | |
// memory | |
// | |
void to_host (T * const host_data) const { | |
HANDLE_ERROR( cudaMemcpy(host_data, device_data, data_size, cudaMemcpyDeviceToHost) ); | |
} | |
// | |
// getters | |
// | |
T * get_pointer() const { return device_data; } | |
}; | |
} | |
#endif//___MSC__CUDA__ARRAY_HPP___ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment