/* * spGPU - Sparse matrices on GPU library. * * Copyright (C) 2010 - 2012 * Davide Barbieri - University of Rome Tor Vergata * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 3 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include "stdio.h" #include "cudalang.h" #include "cudadebug.h" extern "C" { #include "core.h" #include "vector.h" } //#define USE_CUBLAS //#define ASSUME_LOCK_SYNC_PARALLELISM #define BLOCK_SIZE 512 static __device__ double dnrm2ReductionResult[128]; __global__ void spgpuDnrm2_kern(int n, double* x) { __shared__ double sSum[BLOCK_SIZE]; double res = 0; double* lastX = x + n; x += threadIdx.x + blockIdx.x*BLOCK_SIZE; int blockOffset = gridDim.x*BLOCK_SIZE; while (x < lastX) { double x1 = x[0]; res = PREC_DADD(res, PREC_DMUL(x1, x1)); x += blockOffset; } if (threadIdx.x >= 32) sSum[threadIdx.x] = res; __syncthreads(); // Start reduction! if (threadIdx.x < 32) { for (int i=1; imultiProcessorCount, (n+BLOCK_SIZE-1)/BLOCK_SIZE)); #endif double tRes[128]; spgpuDnrm2_kern<<currentStream>>>(n, x);; cudaMemcpyFromSymbol(tRes, dnrm2ReductionResult,blocks*sizeof(double)); for (int i=0; i