70template <
size_t blockSize,
size_t str
ide,
typename T>
71__device__
static void __forceinline__
72cs_blas_hip_warp_reduce_sum(
volatile T *stmp,
76#if CS_HIP_WARP_SIZE == 64
77 if (blockSize >= 128) stmp[tid] += stmp[tid + 64];
79 if (blockSize >= 64) stmp[tid] += stmp[tid + 32];
80 if (blockSize >= 32) stmp[tid] += stmp[tid + 16];
81 if (blockSize >= 16) stmp[tid] += stmp[tid + 8];
82 if (blockSize >= 8) stmp[tid] += stmp[tid + 4];
83 if (blockSize >= 4) stmp[tid] += stmp[tid + 2];
84 if (blockSize >= 2) stmp[tid] += stmp[tid + 1];
89#if CS_HIP_WARP_SIZE == 64
90 if (blockSize >= 128) {
92 for (
size_t i = 0; i < stride; i++)
93 stmp[tid*stride + i] += stmp[(tid + 64)*stride + i];
96 if (blockSize >= 64) {
98 for (
size_t i = 0; i < stride; i++)
99 stmp[tid*stride + i] += stmp[(tid + 32)*stride + i];
101 if (blockSize >= 32) {
103 for (
size_t i = 0; i < stride; i++)
104 stmp[tid*stride + i] += stmp[(tid + 16)*stride + i];
106 if (blockSize >= 16) {
108 for (
size_t i = 0; i < stride; i++)
109 stmp[tid*stride + i] += stmp[(tid + 8)*stride + i];
111 if (blockSize >= 8) {
113 for (
size_t i = 0; i < stride; i++)
114 stmp[tid*stride + i] += stmp[(tid + 4)*stride + i];
116 if (blockSize >= 4) {
118 for (
size_t i = 0; i < stride; i++)
119 stmp[tid*stride + i] += stmp[(tid + 2)*stride + i];
121 if (blockSize >= 2) {
123 for (
size_t i = 0; i < stride; i++)
124 stmp[tid*stride + i] += stmp[(tid + 1)*stride + i];
145template <
size_t blockSize,
size_t str
ide,
typename T>
146__device__
static void __forceinline__
147cs_blas_hip_block_reduce_sum(T *stmp,
157 if (blockSize >= 1024) {
159 stmp[tid] += stmp[tid + 512];
163 if (blockSize >= 512) {
165 stmp[tid] += stmp[tid + 256];
169 if (blockSize >= 256) {
171 stmp[tid] += stmp[tid + 128];
174#if CS_HIP_WARP_SIZE == 32
175 if (blockSize >= 128) {
177 stmp[tid] += stmp[tid + 64];
182 cs_blas_hip_warp_reduce_sum<blockSize, stride>(stmp, tid);
186 cs_blas_hip_warp_reduce_sum<blockSize, stride>(stmp, tid);
192 if (tid == 0) sum_block[blockIdx.x] = stmp[0];
198 if (blockSize >= 1024) {
201 for (
size_t i = 0; i < stride; i++)
202 stmp[tid*stride + i] += stmp[(tid + 512)*stride + i];
206 if (blockSize >= 512) {
209 for (
size_t i = 0; i < stride; i++)
210 stmp[tid*stride + i] += stmp[(tid + 256)*stride + i];
214 if (blockSize >= 256) {
217 for (
size_t i = 0; i < stride; i++)
218 stmp[tid*stride + i] += stmp[(tid + 128)*stride + i];
221#if CS_HIP_WARP_SIZE == 32
222 if (blockSize >= 128) {
225 for (
size_t i = 0; i < stride; i++)
226 stmp[tid*stride + i] += stmp[(tid + 64)*stride + i];
231 cs_blas_hip_warp_reduce_sum<blockSize, stride>(stmp, tid);
234 cs_blas_hip_warp_reduce_sum<blockSize, stride>(stmp, tid);
241 for (
size_t i = 0; i < stride; i++)
242 sum_block[(blockIdx.x)*stride + i] = stmp[i];
260template <
size_t blockSize,
size_t str
ide,
typename T>
261__global__
static void
262cs_blas_hip_reduce_single_block(
size_t n,
266 __shared__ T sdata[blockSize * stride];
268 size_t tid = threadIdx.x;
276 for (
size_t i = threadIdx.x; i < n; i+= blockSize)
277 r_s[0] += g_idata[i];
282 for (
size_t j = blockSize/2; j > CS_HIP_WARP_SIZE; j /= 2) {
284 sdata[tid] += sdata[tid + j];
289 if (tid < CS_HIP_WARP_SIZE) cs_blas_hip_warp_reduce_sum<blockSize, stride>(sdata, tid);
290 if (tid == 0) *g_odata = sdata[0];
296 for (
size_t k = 0;
k < stride;
k++) {
298 sdata[tid*stride +
k] = 0.;
301 for (
size_t i = threadIdx.x; i < n; i+= blockSize) {
303 for (
size_t k = 0;
k < stride;
k++) {
304 r_s[
k] += g_idata[i*stride +
k];
309 for (
size_t k = 0;
k < stride;
k++)
310 sdata[tid*stride +
k] = r_s[
k];
313 for (
size_t j = blockSize/2; j > CS_HIP_WARP_SIZE; j /= 2) {
316 for (
size_t k = 0;
k < stride;
k++)
317 sdata[tid*stride +
k] += sdata[(tid + j)*stride +
k];
322 if (tid < CS_HIP_WARP_SIZE) cs_blas_hip_warp_reduce_sum<blockSize, stride>(sdata, tid);
325 for (
size_t k = 0;
k < stride;
k++)
326 g_odata[
k] = sdata[
k];
349#if defined(__HIPCC__)
364cs_blas_hip_asum(hipStream_t stream,
382cs_blas_hip_dot(hipStream_t stream,
387#if defined(HAVE_HIPBLAS)
402cs_blas_hipblas_asum(hipStream_t stream,
420cs_blas_hipblas_dot(hipStream_t stream,
439cs_blas_hip_scal(hipStream_t stream,
void cs_blas_hip_finalize(void)
Finalize HIP BLAS API.
Definition: cs_blas_hip.cpp:343
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
@ k
Definition: cs_field_pointer.h:68