Add read_arrays definition for CUDA

This commit is contained in:
Tom Deakin 2016-04-26 15:30:37 +01:00
parent 8e534daf8b
commit c22b74ba47
2 changed files with 12 additions and 0 deletions

View File

@ -39,7 +39,16 @@ void CUDAStream<T>::write_arrays(const std::vector<T>& a, const std::vector<T>&
template <class T>
void CUDAStream<T>::read_arrays(std::vector<T>& a, std::vector<T>& b, std::vector<T>& c)
{
// Copy device memory to host
cudaMemcpy(a.data(), d_a, a.size()*sizeof(T), cudaMemcpyDeviceToHost);
check_error();
cudaMemcpy(b.data(), d_b, b.size()*sizeof(T), cudaMemcpyDeviceToHost);
check_error();
cudaMemcpy(c.data(), d_c, c.size()*sizeof(T), cudaMemcpyDeviceToHost);
check_error();
}
template <typename T>
__global__ void copy_kernel(const T * a, T * c)
{

View File

@ -33,6 +33,9 @@ int main(int argc, char *argv[])
stream->copy();
stream->read_arrays(a, b, c);
std::cout << c[105] << std::endl;
delete[] stream;
}