Question

The code of cublas below give us the errors:core dumped while being at "cublasSnrm2(handle,row,dy,incy,de)",could you give some advice?

main.cu

#include <iostream>
#include "cublas.h"
#include "cublas_v2.h"
#include "helper_cuda.h"

using namespace std;

int main(int argc,char *args[])
{
    float y[10] = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}; 

    int dev=0;
    checkCudaErrors(cudaSetDevice(dev));

    //cublas init
    cublasStatus stat;
    cublasInit();

    cublasHandle_t  handle;
    stat = cublasCreate(&handle);
    if (stat !=CUBLAS_STATUS_SUCCESS)
    {
       printf("cublas handle create failed!\n");
       cublasShutdown();
    }   
   float * dy,*de,*e;
   int incy = 1,ONE = 1,row = 10; 
   e = (float *)malloc(sizeof(float)*ONE);
   e[0]=0.0f;

   checkCudaErrors(cudaMalloc(&dy,sizeof(float)*row));
   checkCudaErrors(cudaMalloc(&de,sizeof(float)*ONE));
  checkCudaErrors(cudaMemcpy(dy,y,row*sizeof(float),cudaMemcpyHostToDevice));
  checkCudaErrors(cudaMemcpy(de,e,ONE*sizeof(float),cudaMemcpyHostToDevice));
   stat = cublasSnrm2(handle,row,dy,incy,de);
   if (stat !=CUBLAS_STATUS_SUCCESS)
   {
       printf("norm2 compute failed!\n");
       cublasShutdown();
   }
   checkCudaErrors(cudaMemcpy(e,de,ONE*sizeof(float),cudaMemcpyDeviceToHost));
   std::cout<<e[0]<<endl;
    return 0;
}

makefile is below:

NVIDIA = $(HOME)/NVIDIA_CUDA-5.0_Samples
CUDA = /usr/local/cuda-5.0
NVIDINCADD = -I$(NVIDIA)/common/inc
CUDAINCADD = -I$(CUDA)/include 
CC = -L/usr/lib64/ -lstdc++

GCCOPT = -O2 -fno-rtti -fno-exceptions 
INTELOPT = -O3 -fno-rtti -xW -restrict -fno-alias
DEB = -g
NVCC = -G
ARCH = -arch=sm_35

bcg:main.cu
    nvcc $(DEB) $(NVCC)  $(ARCH) $(CC) -lm  $(NVIDINCADD) $(CUDAINCADD) -lcublas -I./ -o $(@) $(<) 
clean:
    rm -f bcg
    rm -f hyb

My OS is linux redhat 6.2,CUDA's version is 5.0, GPU is K20M.

Was it helpful?

Solution

The problem is here:

cublasSnrm2(handle,row,dy,incy,de);

By default, the last parameter is a host pointer. So either pass e to the snrm2 call rather than de or do this:

cublasSetPointerMode(handle,CUBLAS_POINTER_MODE_DEVICE); 
stat = cublasSnrm2(handle,row,dy,incy,de);

The pointer mode needs to be set to device if you want to pass a device pointer to store the result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top