446 const uint thread_id = omp_get_thread_num();
448 const uint thread_id = 0;
456 for(
uint i = 0;
i < NDim;
i++) {
472 T *d_thread_data_dynamic = 0;
475 const uint gridsize = (
n_total - 1 + blocksize) / blocksize;
478 reduction_kernel<ARCH_BLOCKSIZE_R, Op, NDim, NReduStatic><<<gridsize, blocksize, 0,
gpuStreamList[thread_id]>>>(
482 CHK_ERR(cudaPeekAtLastError());
502 T* d_thread_data_dynamic = 0;
503 if(NReduStatic == 0) {
505 constexpr auto cub_temp_storage_type_size =
sizeof(
typename cub::BlockReduce<T, ARCH_BLOCKSIZE_R, cub::BLOCK_REDUCE_RAKING_COMMUTATIVE_ONLY, 1, 1>::TempStorage);
506 constexpr auto cub_temp_storage_type_size_small =
sizeof(
typename cub::BlockReduce<T, ARCH_BLOCKSIZE_R_SMALL, cub::BLOCK_REDUCE_RAKING_COMMUTATIVE_ONLY, 1, 1>::TempStorage);
509 CHK_ERR(cudaGetDevice(&device_id));
510 cudaDeviceProp deviceProp;
511 CHK_ERR(cudaGetDeviceProperties(&deviceProp, device_id));
514 size_t shared_mem_bytes_per_block_request;
515 if(
n_reductions * cub_temp_storage_type_size <= deviceProp.sharedMemPerBlock){
517 shared_mem_bytes_per_block_request =
n_reductions * cub_temp_storage_type_size;
519 else if(
n_reductions * cub_temp_storage_type_size_small <= deviceProp.sharedMemPerBlock){
521 shared_mem_bytes_per_block_request =
n_reductions * cub_temp_storage_type_size_small;
524 printf(
"The device %d (%s) does not have enough shared memory even for the small blocksize (%d)! The error occurred in %s at line %d\n", device_id, deviceProp.name,
ARCH_BLOCKSIZE_R_SMALL, __FILE__, __LINE__);
528 const uint gridsize = (
n_total - 1 + blocksize) / blocksize;
534 reduction_kernel<ARCH_BLOCKSIZE_R, Op, NDim, 0><<<gridsize, blocksize, shared_mem_bytes_per_block_request,
gpuStreamList[thread_id]>>>(loop_body, d_const_buf, d_buf, d_limits,
n_total,
n_reductions, d_thread_data_dynamic);
537 reduction_kernel<ARCH_BLOCKSIZE_R_SMALL, Op, NDim, 0><<<gridsize, blocksize, shared_mem_bytes_per_block_request,
gpuStreamList[thread_id]>>>(loop_body, d_const_buf, d_buf, d_limits,
n_total,
n_reductions, d_thread_data_dynamic);
540 printf(
"The blocksize (%u) does not match with any of the predetermined block sizes! The error occurred in %s at line %d\n", blocksize, __FILE__, __LINE__);
545 CHK_ERR(cudaPeekAtLastError());
553 const uint gridsize = (
n_total - 1 + blocksize) / blocksize;
556 reduction_kernel<ARCH_BLOCKSIZE_R, Op, NDim, NReduStatic><<<gridsize, blocksize, 0,
gpuStreamList[thread_id]>>>(loop_body, d_const_buf, d_buf, d_limits,
n_total,
n_reductions, d_thread_data_dynamic);
559 CHK_ERR(cudaPeekAtLastError());