Neko
1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
buffer.c
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
35
#include <stdlib.h>
36
37
#include <
device/device_config.h
>
38
#include <
device/opencl/check.h
>
39
#include <
device/opencl/buffer.h
>
40
44
static
opencl_buffer_t
*
buffer_registry
= NULL;
45
46
void
opencl_buffer_reserve
(
opencl_buffer_t
*buf,
size_t
size) {
47
cl_int err;
48
49
if
(size <= buf->size)
50
return
;
51
52
if
(buf->
host
!= NULL) {
53
free(buf->
host
);
54
CL_CHECK
(clReleaseMemObject(buf->
dev
));
55
}
56
57
buf->
host
= malloc(size);
58
buf->
dev
= clCreateBuffer(
glb_ctx
, CL_MEM_READ_WRITE, size, NULL, &err);
59
CL_CHECK
(err);
60
buf->
size
= size;
61
62
if
(!buf->
registered
) {
63
buf->
next
=
buffer_registry
;
64
buffer_registry
= buf;
65
buf->
registered
= 1;
66
}
67
}
68
69
void
opencl_buffer_free_all
(
void
) {
70
opencl_buffer_t
*buf =
buffer_registry
;
71
72
while
(buf != NULL) {
73
opencl_buffer_t
*next = buf->
next
;
74
if
(buf->
host
!= NULL) {
75
free(buf->
host
);
76
buf->
host
= NULL;
77
CL_CHECK
(clReleaseMemObject(buf->
dev
));
78
buf->
dev
= NULL;
79
}
80
buf->
size
= 0;
81
buf->
registered
= 0;
82
buf->
next
= NULL;
83
buf = next;
84
}
85
buffer_registry
= NULL;
86
}
opencl_buffer_free_all
void opencl_buffer_free_all(void)
Definition
buffer.c:69
opencl_buffer_reserve
void opencl_buffer_reserve(opencl_buffer_t *buf, size_t size)
Definition
buffer.c:46
buffer_registry
static cuda_buffer_t * buffer_registry
Definition
buffer.cu:48
device_config.h
glb_ctx
void * glb_ctx
buffer.h
opencl_buffer_t
struct opencl_buffer opencl_buffer_t
Definition
buffer.h:61
check.h
CL_CHECK
#define CL_CHECK(err)
Definition
check.h:12
opencl_buffer::size
size_t size
Definition
buffer.h:57
opencl_buffer::host
void * host
Definition
buffer.h:55
opencl_buffer::registered
int registered
Definition
buffer.h:58
opencl_buffer::dev
cl_mem dev
Definition
buffer.h:56
opencl_buffer::next
struct opencl_buffer * next
Definition
buffer.h:59
src
device
opencl
buffer.c
Generated on
for Neko by
1.15.0