| 30 | if (e != cudaSuccess) { std::fprintf(stderr, "%s: %s\n", w, cudaGetErrorString(e)); std::exit(2); } |
| 31 | } |
| 32 | template <typename T> T* up(const std::vector<T>& h) { |
| 33 | T* d = nullptr; |
| 34 | ck(cudaMalloc(&d, h.size() * sizeof(T) + 64), "malloc"); |
| 35 | ck(cudaMemcpy(d, h.data(), h.size() * sizeof(T), cudaMemcpyHostToDevice), "upload"); |
| 36 | return d; |
| 37 | } |
| 38 | template <typename T> std::vector<T> down(const T* d, size_t n) { |
| 39 | std::vector<T> h(n); |
| 40 | ck(cudaMemcpy(h.data(), d, n * sizeof(T), cudaMemcpyDeviceToHost), "download"); |
no test coverage detected