-1

I've written the following code

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include<iostream>
using namespace std;

__global__ void hello()
{
    printf("Hello"); 
}

int main()
{
    hello<<<1, 7>>>();
    cudaDeviceSynchronize();
    return 0;
}

The code compiles with nvcc -o test test.cu and generates a warning nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning). I go ahead with the execution ./test and there is no output at all. Is there any error in the code? Thanks

Uttaran
  • 59
  • 6
  • 1
    whenever you are having trouble with a CUDA code, it's good practice to use [proper cuda error checking](https://stackoverflow.com/questions/14038589/what-is-the-canonical-way-to-check-for-errors-using-the-cuda-runtime-api) and also run your code with `cuda-memcheck`, **before** asking for help from others. Even if you don't understand the error output, it may be useful for others who are trying to help you. What happens if you run your code with `cuda-memcheck ./test` ? – Robert Crovella Aug 17 '17 at 14:33
  • thanks the problem is solved after a system restart. Maybe something was wrong with the compiler – Uttaran Aug 17 '17 at 15:21

1 Answers1

1

You said your problem was solved after a reboot: a reboot, or at least a X restart is needed after installing nvidia drivers/CUDA.

Anyway, it's a good practice to check errors from CUDA api calls, and reset the device at the end (tools like cuda-memecheck might miss errors otherwise):

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include<iostream>
using namespace std;

#define cudaErr(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort = true)
{
    if (code != cudaSuccess)
    {
        fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
        if (abort) {
            exit(code);
        }
    }
}

__global__ void hello()
{
    printf("Hello"); 
}

int main()
{
    hello<<<1, 7>>>();
    cudaErr(cudaDeviceSynchronize());
    cudaErr(cudaDeviceReset());
    return 0;
}
Robin Thoni
  • 1,651
  • 13
  • 22