imate
C++/CUDA Reference
Loading...
Searching...
No Matches
cuda_api.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <sameli@berkeley.edu>
3 * SPDX-License-Identifier: BSD-3-Clause
4 * SPDX-FileType: SOURCE
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the license found in the LICENSE.txt file in the root
8 * directory of this source tree.
9 */
10
11
12#ifndef _CUDA_UTILITIES_CUDA_API_H_
13#define _CUDA_UTILITIES_CUDA_API_H_
14
15
16// =======
17// Headers
18// =======
19
20#include <cuda_runtime_api.h> // cudaError_t, cudaMalloc, cudaMemcpy,
21 // cudaSuccess, cudaFree
22
23
24// ==========
25// Cuda Tools
26// ==========
27
33
34template<typename ArrayType>
36{
37 public:
38
39 // alloc 1
40 static ArrayType* alloc(const size_t array_size);
41
42 // alloc 2
43 static void alloc(
44 ArrayType*& device_array,
45 const size_t array_size);
46
47 // alloc bytes
48 static void alloc_bytes(
49 void*& device_array,
50 const size_t num_bytes);
51
52 // copy to device
53 static void copy_to_device(
54 const ArrayType* host_array,
55 const size_t array_size,
56 ArrayType* device_array);
57
58 // del
59 static void del(void* device_array);
60
61 // set device
62 static void set_device(int device_id);
63
64 // get device
65 static int get_device();
66};
67
68#endif // _CUDA_UTILITIES_CUDA_API_H_
An interface to CUDA linrary to facilitate working with CUDA, such as memory allocation,...
Definition cuda_api.h:36
static void set_device(int device_id)
Sets the current device in multi-gpu applications.
Definition cuda_api.cu:191
static ArrayType * alloc(const size_t array_size)
Allocates memory on gpu device. This function creates a pointer and returns it.
Definition cuda_api.cu:39
static void del(void *device_array)
Deletes memory on gpu device if its pointer is not NULL, then sets the pointer to NULL.
Definition cuda_api.cu:169
static void alloc_bytes(void *&device_array, const size_t num_bytes)
Allocates memory on gpu device. This function uses an existing given pointer.
Definition cuda_api.cu:118
static int get_device()
Gets the current device in multi-gpu applications.
Definition cuda_api.cu:209
static void copy_to_device(const ArrayType *host_array, const size_t array_size, ArrayType *device_array)
Copies memory on host to device memory.
Definition cuda_api.cu:145