1#include "hip/hip_runtime.h"
69template <
typename T,
size_t str
ide>
77 for (
cs_lnum_t id = blockIdx.x * blockDim.x + threadIdx.x;
id < n;
78 id += blockDim.x * gridDim.x) {
79 for (
int j = 0; j < size_arrs; j++) {
80 for (
size_t k = 0;
k < stride;
k++) {
81 array_ptrs[j][
id*stride +
k] = ref_val;
87template <
typename T,
size_t str
ide>
95 for (
cs_lnum_t id = blockIdx.x * blockDim.x + threadIdx.x;
id < n;
96 id += blockDim.x * gridDim.x) {
97 for (
int j = 0; j < size_arrs; j++) {
98 for (
size_t k = 0;
k < stride;
k++) {
99 array_ptrs[j][
id*stride +
k] = ref_val[
k];
105template <
typename T,
size_t str
ide>
112 for (
cs_lnum_t id = blockIdx.x * blockDim.x + threadIdx.x;
id < n;
113 id += blockDim.x * gridDim.x) {
114 for (
size_t k = 0;
k < stride;
k++) {
115 array[
id*stride +
k] = ref_val;
120template <
typename T,
size_t str
ide>
127 for (
cs_lnum_t id = blockIdx.x * blockDim.x + threadIdx.x;
id < n;
128 id += blockDim.x * gridDim.x) {
129 for (
size_t k = 0;
k < stride;
k++) {
130 array[
id*stride +
k] = *ref_val;
135template <
typename T,
size_t str
ide>
140 T c =
static_cast<T
>(0);
143 for (
cs_lnum_t id = blockIdx.x * blockDim.x + threadIdx.x;
id < n;
144 id += blockDim.x * gridDim.x) {
145 for (
size_t k = 0;
k < stride;
k++) {
146 array[
id*stride +
k] = c;
169template <
typename T,
size_t stride,
typename... Arrays>
177 const long block_size_ = 256;
178 const long grid_size_ = (n_elts % block_size_) ?
179 n_elts/block_size_ + 1 : n_elts/block_size_;
182 const int size_arrs =
sizeof...(arrays);
183 T* _array_ptrs[] = {arrays ...};
187 hipGraphExec_t graph_exec = NULL;
189 CS_HIP_CHECK(hipStreamBeginCapture(stream, hipStreamCaptureModeGlobal));
190 for (
int j = 0; j < size_arrs; j++) {
191 hip_kernel_set_value<T, stride><<<grid_size_, block_size_, 0, stream>>>
192 (n_elts, ref_val, _array_ptrs[j]);
194 CS_HIP_CHECK(hipStreamEndCapture(stream, &graph));
196 CS_HIP_CHECK(hipGraphInstantiate(&graph_exec, graph,
197 nullptr,
nullptr, 0));
198 CS_HIP_CHECK(hipGraphLaunch(graph_exec, stream));
204 CS_HIP_CHECK(hipStreamSynchronize(stream));
205 CS_HIP_CHECK(hipGetLastError());
207 CS_HIP_CHECK(hipGraphDestroy(graph));
208 CS_HIP_CHECK(hipGraphExecDestroy(graph_exec));
212 hip_kernel_set_value<T, stride><<<grid_size_, block_size_, 0, stream>>>
213 (n_elts, ref_val, _array_ptrs[0]);
215 if (async ==
false) {
216 CS_HIP_CHECK(hipStreamSynchronize(stream));
217 CS_HIP_CHECK(hipGetLastError());
240template <
typename T,
size_t stride,
typename... Arrays>
248 const long block_size_ = 256;
249 const long grid_size_ = (n_elts % block_size_) ?
250 n_elts/block_size_ + 1 : n_elts/block_size_;
253 const int size_arrs =
sizeof...(arrays);
254 T* _array_ptrs[] = {arrays ...};
258 hipGraphExec_t graph_exec = NULL;
260 CS_HIP_CHECK(hipStreamBeginCapture(stream, hipStreamCaptureModeGlobal));
262 for (
int j = 0; j < size_arrs; j++) {
263 hip_kernel_set_value<T, stride><<<grid_size_, block_size_, 0, stream>>>
264 (n_elts, ref_val, _array_ptrs[j]);
266 CS_HIP_CHECK(hipStreamEndCapture(stream, &graph));
268 CS_HIP_CHECK(hipGraphInstantiate(&graph_exec, graph,
269 nullptr,
nullptr, 0));
270 CS_HIP_CHECK(hipGraphLaunch(graph_exec, stream));
276 CS_HIP_CHECK(hipStreamSynchronize(stream));
277 CS_HIP_CHECK(hipGetLastError());
279 CS_HIP_CHECK(hipGraphDestroy(graph));
280 CS_HIP_CHECK(hipGraphExecDestroy(graph_exec));
284 hip_kernel_set_value<T, stride><<<grid_size_, block_size_, 0, stream>>>
285 (n_elts, ref_val, _array_ptrs[0]);
287 if (async ==
false) {
288 CS_HIP_CHECK(hipStreamSynchronize(stream));
289 CS_HIP_CHECK(hipGetLastError());
312template <
typename T,
size_t stride,
typename... Arrays>
319 const long block_size_ = 256;
320 const long grid_size_ = (n_elts % block_size_) ?
321 n_elts/block_size_ + 1 : n_elts/block_size_;
324 const int size_arrs =
sizeof...(arrays);
325 T* _array_ptrs[] = {arrays ...};
329 hipGraphExec_t graph_exec = NULL;
331 CS_HIP_CHECK(hipStreamBeginCapture(stream, hipStreamCaptureModeGlobal));
332 for (
int j = 0; j < size_arrs; j++) {
333 cs_hip_kernel_set_zero<T, stride><<<grid_size_, block_size_, 0, stream>>>
334 (n_elts, _array_ptrs[j]);
336 CS_HIP_CHECK(hipStreamEndCapture(stream, &graph));
338 CS_HIP_CHECK(hipGraphInstantiate(&graph_exec, graph,
339 nullptr,
nullptr, 0));
340 CS_HIP_CHECK(hipGraphLaunch(graph_exec, stream));
346 CS_HIP_CHECK(hipStreamSynchronize(stream));
347 CS_HIP_CHECK(hipGetLastError());
349 CS_HIP_CHECK(hipGraphDestroy(graph));
350 CS_HIP_CHECK(hipGraphExecDestroy(graph_exec));
354 cs_hip_kernel_set_zero<T, stride><<<grid_size_, block_size_, 0, stream>>>
355 (n_elts, _array_ptrs[0]);
357 if (async ==
false) {
358 CS_HIP_CHECK(hipStreamSynchronize(stream));
359 CS_HIP_CHECK(hipGetLastError());
387 CS_HIP_CHECK(hipMemcpyAsync(dest, src, size*
sizeof(T),
388 hipMemcpyDeviceToDevice, stream));
389 if (async ==
false) {
390 CS_HIP_CHECK(hipStreamSynchronize(stream));
391 CS_HIP_CHECK(hipGetLastError());
void cs_arrays_set_zero(hipStream_t stream, bool async, cs_lnum_t n_elts, Arrays &&... arrays)
Assign values to all elements of multiple arrays. ref_val is input as a pointer or an array.
Definition: cs_array_hip.h:314
__global__ void cs_hip_kernel_set_zero(cs_lnum_t n, T *array)
Definition: cs_array_hip.h:137
void cs_array_copy(hipStream_t stream, bool async, const cs_lnum_t size, const T *src, T *dest)
Copy values from an array to another of the same dimensions.
Definition: cs_array_hip.h:381
__global__ void hip_kernel_set_value(cs_lnum_t n, const T ref_val, const int size_arrs, T **array_ptrs)
Definition: cs_array_hip.h:71
void cs_arrays_set_value(hipStream_t stream, bool async, cs_lnum_t n_elts, T *ref_val, Arrays &&... arrays)
Assign values to all elements of multiple arrays. ref_val is input as a pointer or an array.
Definition: cs_array_hip.h:171
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
@ k
Definition: cs_field_pointer.h:68