1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-04 19:25:56 +01:00

begin end lamda

This commit is contained in:
Peter Boyle 2018-03-24 19:31:45 -04:00
parent 1f70cedbab
commit 5412628ea6

View File

@ -80,11 +80,11 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
constexpr uint32_t gpu_threads = 8; constexpr uint32_t gpu_threads = 8;
template<typename lambda> __global__ template<typename lambda> __global__
void LambdaApply(uint64_t Num, lambda Lambda) void LambdaApply(uint64_t base, uint64_t Num, lambda Lambda)
{ {
uint64_t ss = blockIdx.x*blockDim.x + threadIdx.x; uint64_t ss = blockIdx.x*blockDim.x + threadIdx.x;
if ( ss < Num ) { if ( ss < Num ) {
Lambda(ss); Lambda(ss+base);
} }
} }
@ -95,15 +95,16 @@ void LambdaApply(uint64_t Num, lambda Lambda)
auto lambda = [=] accelerator (Iterator iterator) mutable { \ auto lambda = [=] accelerator (Iterator iterator) mutable { \
__VA_ARGS__; \ __VA_ARGS__; \
}; \ }; \
Iterator num = range.end(); \ Iterator num = range.end(); \
Iterator base = range.begin(); \
Iterator num_block = (num + gpu_threads - 1)/gpu_threads; \ Iterator num_block = (num + gpu_threads - 1)/gpu_threads; \
LambdaApply<<<num_block,gpu_threads>>>(num,lambda); \ LambdaApply<<<num_block,gpu_threads>>>(base,num_,lambda); \
cudaError err = cudaGetLastError(); \
cudaDeviceSynchronize(); \ cudaDeviceSynchronize(); \
cudaError err = cudaGetLastError(); \
if ( cudaSuccess != err ) { \ if ( cudaSuccess != err ) { \
printf("Cuda error %s\n",cudaGetErrorString( err )); \ printf("Cuda error %s\n",cudaGetErrorString( err )); \
exit(0); \ exit(0); \
} \ }
#define cpu_loop( iterator, range, ... ) thread_loop( (auto iterator = range.begin();iterator<range.end();iterator++), { __VA_ARGS__ }); #define cpu_loop( iterator, range, ... ) thread_loop( (auto iterator = range.begin();iterator<range.end();iterator++), { __VA_ARGS__ });