CUDA and CUSP

Hello
I’m new to CUDA and new to CUSP. I’m trying to get everything to work correctly to make the most of using CUSP. However, I’ve bumped into some strange behavior which I don’t have a clue where to look into to solve it. I’ve installed CUDA v4.1, Thrust v1.5.1 and Cusp v0.3.0

I then tried to run some of the example cusp programs and trouble began.
For example, I have compiled the array1d.cu example and executed it.
The result should be as follows,
array1d <10>
1
1
1
1
1
2
2
2
2
2
array1d <10>
1
1
1
1
1
1
1
1
1

         1

but instead I get

array1d <10>
-572662307
-572662307
-572662307
-572662307
-572662307
-572662307
-572662307
-572662307
-572662307
-572662307
array1d <10>
-572662307
-572662307
-572662307
-572662307
-572662307
-572662307
-572662307
-572662307
-572662307
-572662307
This looks to me like the memory assignment has gone wrong. I modified
the code to use host_memory instead of device_memory, compiled and
executed and got the correct result. It would appear as if something
goes wrong when attempting to use the GPU. I’m running this on a Tesla
2070 GPU.
Any insights into what I might be missing or doing wrong are
appreciated.

I run that example without any problem… can you check if there is any cuda error ?

inline void checkCUDAError(std::string msg) {

 cudaError_t err = cudaGetLastError();

 if( cudaSuccess != err)

 {

    std::cerr << "Cuda error during " <<  msg << ": " << cudaGetErrorString(err);

    exit(EXIT_FAILURE);

 }

}

put checkCUDAError(“some message”) before and after the kernel call… I haven’t test it but you get the idea

Thanks for your reply.

I have done as you suggested. The code I now have looks like this:

#include <cusp/array1d.h>

#include <cusp/blas.h>

#include <cusp/copy.h>

#include <cusp/print.h>

// This example shows how to create views to an array container.

// Views act like containers but do not own the underlying data.

// Like pointers, views are *lightweight* objects that *reference* data.

inline void checkCUDAError(std::string msg) {

 cudaError_t err = cudaGetLastError();

 if( cudaSuccess != err)

 {

    std::cerr << "Cuda error during " <<  msg << ": " << cudaGetErrorString(err);

    exit(EXIT_FAILURE);

 }

}

int main(void)

{

  // define array container type

  typedef cusp::array1d<int, cusp::device_memory> Array;

  checkCUDAError("-1");

  // define array view type

  typedef Array::view View;

  checkCUDAError("0");

  // allocate array1d container with 10 elements

  Array array(10,0);

  checkCUDAError("1");

  // create view to the first 5 elements of the array

  View first_half(array.begin(), array.begin() + 5);

  checkCUDAError("2");

  // create view to the last 5 elements of the array

  View last_half(array.begin() + 5, array.end());

  checkCUDAError("3");

  // fill the first half of the array with 1s

  cusp::blas::fill(first_half, 1);

    checkCUDAError("4");

  // fill the first half of the array with 2s

  cusp::blas::fill(last_half,  2);

  checkCUDAError("5");

  // print the array

  cusp::print(array);

  checkCUDAError("6");

  // copy the first half to the last half

  cusp::copy(first_half, last_half);

    checkCUDAError("7");

  // print the array

  cusp::print(array);

return 0;

}

It reports error after allocating the array (error label 1) with “invalid configuration argument”. I’ve googled this error and seems to be related to memory allocation, or something to do with grid or block dimensions. On the other hand, I found some stuff relating it to driver versions. I’ll ask the system admin to look into it anyhow. Does the “invalid configuration argument” error indicate anything to you? I’m quite the CUDA newbie so I’m not sure if it this error can mean something else.

Thanks