Neko 1.99.6
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
buffer.cu
Go to the documentation of this file.
1/*
2 Copyright (c) 2026, The Neko Authors
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above
13 copyright notice, this list of conditions and the following
14 disclaimer in the documentation and/or other materials provided
15 with the distribution.
16
17 * Neither the name of the authors nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33*/
34
36#include <device/cuda/check.h>
37#include <device/cuda/buffer.h>
38
39#ifdef HAVE_NVSHMEM
40#include <nvshmem.h>
41#endif
42
43extern "C" {
44
49
51
52 if (size <= buf->size)
53 return;
54
55 if (buf->dev != NULL) {
56 if (buf->host != NULL)
58#ifdef HAVE_NVSHMEM
59 if (buf->symm)
60 nvshmem_free(buf->dev);
61 else
62 CUDA_CHECK(cudaFree(buf->dev));
63#else
64 CUDA_CHECK(cudaFree(buf->dev));
65#endif
66 }
67
68 if (!buf->dev_only)
69 CUDA_CHECK(cudaMallocHost(&buf->host, size));
70#ifdef HAVE_NVSHMEM
71 if (buf->symm)
72 buf->dev = nvshmem_malloc(size);
73 else
74 CUDA_CHECK(cudaMalloc(&buf->dev, size));
75#else
76 CUDA_CHECK(cudaMalloc(&buf->dev, size));
77#endif
78 buf->size = size;
79
80 if (!buf->registered) {
81 buf->next = buffer_registry;
83 buf->registered = 1;
84 }
85 }
86
89
90 while (buf != NULL) {
91 cuda_buffer_t *next = buf->next;
92 if (buf->host != NULL) {
94 buf->host = NULL;
95 }
96 if (buf->dev != NULL) {
97#ifdef HAVE_NVSHMEM
98 if (buf->symm)
99 nvshmem_free(buf->dev);
100 else
101 CUDA_CHECK(cudaFree(buf->dev));
102#else
103 CUDA_CHECK(cudaFree(buf->dev));
104#endif
105 buf->dev = NULL;
106 }
107 buf->size = 0;
108 buf->registered = 0;
109 buf->next = NULL;
110 buf = next;
111 }
113 }
114
115}
static cuda_buffer_t * buffer_registry
Definition buffer.cu:48
void cuda_buffer_free_all(void)
Definition buffer.cu:87
void cuda_buffer_reserve(cuda_buffer_t *buf, size_t size)
Definition buffer.cu:50
__global__ void ale_add_kinematics_kernel(const int n, T *__restrict__ wx, T *__restrict__ wy, T *__restrict__ wz, const T *__restrict__ x_ref, const T *__restrict__ y_ref, const T *__restrict__ z_ref, const T *__restrict__ phi, const T *__restrict__ x, const T *__restrict__ y, const T *__restrict__ z, const kinematics_params_t kin_params)
#define CUDA_CHECK(err)
Definition check.h:6
struct cuda_buffer * next
Definition buffer.h:58
int registered
Definition buffer.h:57