55#if defined(__CUDACC__)
70template <
size_t blockSize,
size_t str
ide,
typename T>
71__device__
static void __forceinline__
72cs_blas_cuda_warp_reduce_sum(
volatile T *stmp,
77 if (blockSize >= 64) stmp[tid] += stmp[tid + 32];
78 if (blockSize >= 32) stmp[tid] += stmp[tid + 16];
79 if (blockSize >= 16) stmp[tid] += stmp[tid + 8];
80 if (blockSize >= 8) stmp[tid] += stmp[tid + 4];
81 if (blockSize >= 4) stmp[tid] += stmp[tid + 2];
82 if (blockSize >= 2) stmp[tid] += stmp[tid + 1];
87 if (blockSize >= 64) {
89 for (
size_t i = 0; i < stride; i++)
90 stmp[tid*stride + i] += stmp[(tid + 32)*stride + i];
92 if (blockSize >= 32) {
94 for (
size_t i = 0; i < stride; i++)
95 stmp[tid*stride + i] += stmp[(tid + 16)*stride + i];
97 if (blockSize >= 16) {
99 for (
size_t i = 0; i < stride; i++)
100 stmp[tid*stride + i] += stmp[(tid + 8)*stride + i];
102 if (blockSize >= 8) {
104 for (
size_t i = 0; i < stride; i++)
105 stmp[tid*stride + i] += stmp[(tid + 4)*stride + i];
107 if (blockSize >= 4) {
109 for (
size_t i = 0; i < stride; i++)
110 stmp[tid*stride + i] += stmp[(tid + 2)*stride + i];
112 if (blockSize >= 2) {
114 for (
size_t i = 0; i < stride; i++)
115 stmp[tid*stride + i] += stmp[(tid + 1)*stride + i];
140template <
size_t blockSize,
size_t str
ide,
typename T>
141__device__
static void __forceinline__
142cs_blas_cuda_block_reduce_sum(T *stmp,
152 if (blockSize >= 1024) {
154 stmp[tid] += stmp[tid + 512];
158 if (blockSize >= 512) {
160 stmp[tid] += stmp[tid + 256];
164 if (blockSize >= 256) {
166 stmp[tid] += stmp[tid + 128];
169 if (blockSize >= 128) {
171 stmp[tid] += stmp[tid + 64];
176 cs_blas_cuda_warp_reduce_sum<blockSize, stride>(stmp, tid);
181 if (tid == 0) sum_block[blockIdx.x] = stmp[0];
187 if (blockSize >= 1024) {
190 for (
size_t i = 0; i < stride; i++)
191 stmp[tid*stride + i] += stmp[(tid + 512)*stride + i];
195 if (blockSize >= 512) {
198 for (
size_t i = 0; i < stride; i++)
199 stmp[tid*stride + i] += stmp[(tid + 256)*stride + i];
203 if (blockSize >= 256) {
206 for (
size_t i = 0; i < stride; i++)
207 stmp[tid*stride + i] += stmp[(tid + 128)*stride + i];
210 if (blockSize >= 128) {
213 for (
size_t i = 0; i < stride; i++)
214 stmp[tid*stride + i] += stmp[(tid + 64)*stride + i];
219 cs_blas_cuda_warp_reduce_sum<blockSize, stride>(stmp, tid);
225 for (
size_t i = 0; i < stride; i++)
226 sum_block[(blockIdx.x)*stride + i] = stmp[i];
244template <
size_t blockSize,
size_t str
ide,
typename T>
245__global__
static void
246cs_blas_cuda_reduce_single_block(
size_t n,
250 __shared__ T sdata[blockSize * stride];
252 size_t tid = threadIdx.x;
260 for (
size_t i = threadIdx.x; i < n; i+= blockSize)
261 r_s[0] += g_idata[i];
266 for (
size_t j = blockSize/2; j > CS_CUDA_WARP_SIZE; j /= 2) {
268 sdata[tid] += sdata[tid + j];
273 if (tid < 32) cs_blas_cuda_warp_reduce_sum<blockSize, stride>(sdata, tid);
274 if (tid == 0) *g_odata = sdata[0];
280 for (
size_t k = 0;
k < stride;
k++) {
282 sdata[tid*stride +
k] = 0.;
285 for (
size_t i = threadIdx.x; i < n; i+= blockSize) {
287 for (
size_t k = 0;
k < stride;
k++) {
288 r_s[
k] += g_idata[i*stride +
k];
293 for (
size_t k = 0;
k < stride;
k++)
294 sdata[tid*stride +
k] = r_s[
k];
297 for (
size_t j = blockSize/2; j > CS_CUDA_WARP_SIZE; j /= 2) {
300 for (
size_t k = 0;
k < stride;
k++)
301 sdata[tid*stride +
k] += sdata[(tid + j)*stride +
k];
306 if (tid < 32) cs_blas_cuda_warp_reduce_sum<blockSize, stride>(sdata, tid);
309 for (
size_t k = 0;
k < stride;
k++)
310 g_odata[
k] = sdata[
k];
333#if defined(__CUDACC__)
348cs_blas_cuda_asum(cudaStream_t stream,
366cs_blas_cuda_dot(cudaStream_t stream,
371#if defined(HAVE_CUBLAS)
386cs_blas_cublas_asum(cudaStream_t stream,
404cs_blas_cublas_dot(cudaStream_t stream,
423cs_blas_cuda_scal(cudaStream_t stream,
void cs_blas_cuda_finalize(void)
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