|
|
|
@ -32,8 +32,9 @@ extern "C"
|
|
|
|
|
__global__ void spgpuCaxpby_krn(cuFloatComplex *z, int n, cuFloatComplex beta, cuFloatComplex *y, cuFloatComplex alpha, cuFloatComplex* x)
|
|
|
|
|
{
|
|
|
|
|
int id = threadIdx.x + BLOCK_SIZE*blockIdx.x;
|
|
|
|
|
|
|
|
|
|
if (id < n)
|
|
|
|
|
unsigned int gridSize = blockDim.x * gridDim.x;
|
|
|
|
|
for ( ; id < n; id +=gridSize)
|
|
|
|
|
//if (id,n)
|
|
|
|
|
{
|
|
|
|
|
// Since z, x and y are accessed with the same offset by the same thread,
|
|
|
|
|
// and the write to z follows the x and y read, x, y and z can share the same base address (in-place computing).
|
|
|
|
@ -45,7 +46,30 @@ __global__ void spgpuCaxpby_krn(cuFloatComplex *z, int n, cuFloatComplex beta, c
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
|
void spgpuCaxpby(spgpuHandle_t handle,
|
|
|
|
|
__device cuFloatComplex *z,
|
|
|
|
|
int n,
|
|
|
|
|
cuFloatComplex beta,
|
|
|
|
|
__device cuFloatComplex *y,
|
|
|
|
|
cuFloatComplex alpha,
|
|
|
|
|
__device cuFloatComplex* x)
|
|
|
|
|
{
|
|
|
|
|
int msize = (n+BLOCK_SIZE-1)/BLOCK_SIZE;
|
|
|
|
|
int num_mp, max_threads_mp, num_blocks_mp, num_blocks;
|
|
|
|
|
dim3 block(BLOCK_SIZE);
|
|
|
|
|
cudaDeviceProp deviceProp;
|
|
|
|
|
cudaGetDeviceProperties(&deviceProp, 0);
|
|
|
|
|
num_mp = deviceProp.multiProcessorCount;
|
|
|
|
|
max_threads_mp = deviceProp.maxThreadsPerMultiProcessor;
|
|
|
|
|
num_blocks_mp = max_threads_mp/BLOCK_SIZE;
|
|
|
|
|
num_blocks = num_blocks_mp*num_mp;
|
|
|
|
|
dim3 grid(num_blocks);
|
|
|
|
|
|
|
|
|
|
spgpuCaxpby_krn<<<grid, block, 0, handle->currentStream>>>(z, n, beta, y, alpha, x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
void spgpuCaxpby_(spgpuHandle_t handle,
|
|
|
|
|
__device cuFloatComplex *z,
|
|
|
|
|
int n,
|
|
|
|
@ -55,9 +79,15 @@ void spgpuCaxpby_(spgpuHandle_t handle,
|
|
|
|
|
__device cuFloatComplex* x)
|
|
|
|
|
{
|
|
|
|
|
int msize = (n+BLOCK_SIZE-1)/BLOCK_SIZE;
|
|
|
|
|
|
|
|
|
|
int num_mp, max_threads_mp, num_blocks_mp, num_blocks;
|
|
|
|
|
dim3 block(BLOCK_SIZE);
|
|
|
|
|
dim3 grid(msize);
|
|
|
|
|
cudaDeviceProp deviceProp;
|
|
|
|
|
cudaGetDeviceProperties(&deviceProp, 0);
|
|
|
|
|
num_mp = deviceProp.multiProcessorCount;
|
|
|
|
|
max_threads_mp = deviceProp.maxThreadsPerMultiProcessor;
|
|
|
|
|
num_blocks_mp = max_threads_mp/BLOCK_SIZE;
|
|
|
|
|
num_blocks = num_blocks_mp*num_mp;
|
|
|
|
|
dim3 grid(num_blocks);
|
|
|
|
|
|
|
|
|
|
spgpuCaxpby_krn<<<grid, block, 0, handle->currentStream>>>(z, n, beta, y, alpha, x);
|
|
|
|
|
}
|
|
|
|
@ -86,7 +116,7 @@ void spgpuCaxpby(spgpuHandle_t handle,
|
|
|
|
|
|
|
|
|
|
cudaCheckError("CUDA error on saxpby");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
void spgpuCmaxpby(spgpuHandle_t handle,
|
|
|
|
|
__device cuFloatComplex *z,
|
|
|
|
|
int n,
|
|
|
|
|