milupHPC documentation
  • include
  • cuda_utils
cuda_runtime.h
Go to the documentation of this file.
1
10#ifndef MILUPHPC_CUDA_RUNTIME_H
11#define MILUPHPC_CUDA_RUNTIME_H
12
13#include "cuda_utilities.cuh"
14#include "../parameter.h"
15
16namespace cuda {
17
29 template <typename T>
30 void copy(T *h_var, T *d_var, std::size_t count = 1, To::Target copyTo = To::device) {
31
32 switch (copyTo) {
33 case To::device: {
34 gpuErrorcheck(cudaMemcpy(d_var, h_var, count * sizeof(T), cudaMemcpyHostToDevice));
35 } break;
36 case To::host: {
37 gpuErrorcheck(cudaMemcpy(h_var, d_var, count * sizeof(T), cudaMemcpyDeviceToHost));
38 } break;
39 default: {
40 printf("cuda::copy Target not available!\n");
41 }
42 }
43 }
44
55 template <typename T>
56 void set(T *d_var, T val, std::size_t count = 1) {
57 gpuErrorcheck(cudaMemset(d_var, val, count * sizeof(T)));
58 }
59
69 template <typename T>
70 void malloc(T *&d_var, std::size_t count) {
71 gpuErrorcheck(cudaMalloc((void**)&d_var, count * sizeof(T)));
72 }
73
80 template <typename T>
81 void free(T *d_var) {
82 gpuErrorcheck(cudaFree(d_var));
83 }
84
85}
86
87
88#endif //MILUPHPC_CUDA_RUNTIME_H
cuda_utilities.cuh
CUDA utilities.
gpuErrorcheck
#define gpuErrorcheck(ans)
check CUDA call
Definition: cuda_utilities.cuh:41
cuda
Definition: cuda_launcher.cuh:101
cuda::copy
void copy(T *h_var, T *d_var, std::size_t count=1, To::Target copyTo=To::device)
Copy between host and device and vice-versa.
Definition: cuda_runtime.h:30
cuda::set
void set(T *d_var, T val, std::size_t count=1)
Set device memory to a specific value.
Definition: cuda_runtime.h:56
cuda::free
void free(T *d_var)
Free device memory.
Definition: cuda_runtime.h:81
cuda::malloc
void malloc(T *&d_var, std::size_t count)
Allocate device memory.
Definition: cuda_runtime.h:70
To::Target
Target
Definition: parameter.h:164
To::device
@ device
Definition: parameter.h:165
To::host
@ host
Definition: parameter.h:165

milupHPC - include/cuda_utils/cuda_runtime.h Source File
Generated on Wed Aug 31 2022 12:16:52 by Doxygen 1.9.3