DriverAPI SEG fault from cudalib

Hi all,

I am trying make 10X10 matrix of floats in GPU and trying to do memcpy2D to GPU from a linear array of 400 bytes
I am getting seg fault from " in pthread_attr_setdetachstate () from /usr/lib64/libcuda.so.1" from cud lib .I am exactly following the Nvidia cuda programming guide. I try to change pcopy.WidthInBytes=40;
pcopy.Height=10 to test what is causing it.

Can anyone shed some light on this please??

Regards and thanks
more_ more_parallel

I am passing the code for your verification.

iint main()
{
void *pp;
unsigned int msize=0;
CUdevice dev;
CUcontext ct;
CUresult res;

    cuInit(0);
    if((cuDeviceGet (&dev,0))!=CUDA_SUCCESS)
    {
            std::cout<< "error in device get"<<std::endl;
    }
    res=cuCtxCreate (&ct,0,dev);
    if(res!=CUDA_SUCCESS)
    {
            std::cout<< "error in context creation "<<res<<std::endl;
    }

    void  *p2DArray;
    CUarray a1;
    CUdeviceptr  Hdptr;
    CUDA_MEMCPY2D pcopy;
    CUDA_ARRAY_DESCRIPTOR desc;
    desc.Format = CU_AD_FORMAT_FLOAT;
    desc.NumChannels = 1;
    desc.Width = 10;
    desc.Height = 10;

    res=cuMemAllocHost (&p2DArray,400);
    if(res!=CUDA_SUCCESS)
    {
            std::cout<< "error in MemAlloc"<<res<<std::endl;
    }
    res=cuArrayCreate(&a1,&desc);
    if(res!=CUDA_SUCCESS)
    {
            std::cout<< "error in ArrayCreate"<<res<<std::endl;
    }

    pcopy.srcMemoryType = CU_MEMORYTYPE_HOST;
    pcopy.srcHost=p2DArray;
    pcopy.srcPitch=400;
    pcopy.dstMemoryType = CU_MEMORYTYPE_ARRAY;
    pcopy.dstArray=a1;
    pcopy.WidthInBytes=40;
    pcopy.Height=10;

    res=cuMemcpy2D(&pcopy);
    if(res!=CUDA_SUCCESS)
    {
            std::cout<< "error in copy2d array "<<res<<std::endl;
    }

}