NVCC ignoring CUDA code?

mib1413456

I have just installed CUDA 5.5 on my notebook and trying out using NVCC to compile a basic hello world program from this link http://computer-graphics.se/hello-world-for-cuda.html

The code I'm trying out is this:

// This is the REAL "hello world" for CUDA!
// It takes the string "Hello ", prints it, then passes it to CUDA with an array
// of offsets. Then the offsets are added in parallel to produce the string "World!"
// By Ingemar Ragnemalm 2010

#include <stdio.h>

const int N = 16; 
const int blocksize = 16; 

__global__ 
void hello(char *a, int *b) 
{
    a[threadIdx.x] += b[threadIdx.x];
}

int main()
{
    char a[N] = "Hello \0\0\0\0\0\0";
    int b[N] = {15, 10, 6, 0, -11, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

    char *ad;
    int *bd;
    const int csize = N*sizeof(char);
    const int isize = N*sizeof(int);

    printf("%s", a);

    cudaMalloc( (void**)&ad, csize ); 
    cudaMalloc( (void**)&bd, isize ); 
    cudaMemcpy( ad, a, csize, cudaMemcpyHostToDevice ); 
    cudaMemcpy( bd, b, isize, cudaMemcpyHostToDevice ); 

    dim3 dimBlock( blocksize, 1 );
    dim3 dimGrid( 1, 1 );
    hello<<<dimGrid, dimBlock>>>(ad, bd);
    cudaMemcpy( a, ad, csize, cudaMemcpyDeviceToHost ); 
    cudaFree( ad );
    cudaFree( bd );

    printf("%s\n", a);
    return EXIT_SUCCESS;
}

It is supposed to print out "Hello world!", but after I compiled using "nvcc hello.cu -o a.out", my output is "Hello Hello", can someone tell me what is going on?

talonmies

This was caused by a broken CUDA driver installation. A corrected installation allowed what was otherwise correct code to run without error.

[This community wiki entry was assembled from comments to get this question off the unanswered queue]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

cuda - How does nvcc compile __host__ code?

From Dev

CUDA: nvcc without CUDA toolkit

From Dev

CUDA: nvcc without CUDA toolkit

From Dev

CUDA nvcc building chain of libraries

From Dev

CUDA - nvcc -G - if not working properly

From Dev

Nvcc -v fails but CUDA 7.0 installed and nvcc present

From Dev

NVCC CUDA cross compiling cannot find "-lcudart"

From Java

Different CUDA versions shown by nvcc and NVIDIA-smi

From Dev

Using CMakes CHECK_CXX_COMPILER_FLAG with nvcc/cuda

From Dev

How to Get CUDA Toolkit Version at Compile Time Without nvcc?

From Dev

How to set CMake CUDA_NVCC_FLAGS per .cu file

From Dev

NVCC compile to ptx using CMAKE's cuda_compile_ptx

From Dev

How to set CMake CUDA_NVCC_FLAGS per .cu file

From Dev

Using CMakes CHECK_CXX_COMPILER_FLAG with nvcc/cuda

From Dev

nvcc error, "no command" verifying installation of CUDA 10 on Debian 9 Stretch

From Dev

Python code ignoring if statements

From Dev

Code ignoring if statements - C++

From Dev

Code is ignoring IF command in C, Issues with FOR

From Dev

Why is the code ignoring one of the IF requirements?

From Dev

Code execution on CUDA/CPU

From Dev

optimizing CUDA code with branches

From Dev

optimizing CUDA code with branches

From Dev

CUDA : stencil code not working

From Dev

NVCC compilation options for generating the best code (using JIT)

From Dev

What should I do when (CUDA 7.5's) nvcc/cudafe++ crashes with a segfault?

From Dev

Can't get rid of "warning: command line option ‘-std=c++11’" using nvcc/CUDA/cmake

From Dev

After installing CUDA on Tegra Tx1 and sourcing the bashrc it will not find NVCC

From Dev

CUDA Segmentation fault in threads with no CUDA code

From Dev

visual studio code debuggin mocha is ignoring breakpoints

Related Related

  1. 1

    cuda - How does nvcc compile __host__ code?

  2. 2

    CUDA: nvcc without CUDA toolkit

  3. 3

    CUDA: nvcc without CUDA toolkit

  4. 4

    CUDA nvcc building chain of libraries

  5. 5

    CUDA - nvcc -G - if not working properly

  6. 6

    Nvcc -v fails but CUDA 7.0 installed and nvcc present

  7. 7

    NVCC CUDA cross compiling cannot find "-lcudart"

  8. 8

    Different CUDA versions shown by nvcc and NVIDIA-smi

  9. 9

    Using CMakes CHECK_CXX_COMPILER_FLAG with nvcc/cuda

  10. 10

    How to Get CUDA Toolkit Version at Compile Time Without nvcc?

  11. 11

    How to set CMake CUDA_NVCC_FLAGS per .cu file

  12. 12

    NVCC compile to ptx using CMAKE's cuda_compile_ptx

  13. 13

    How to set CMake CUDA_NVCC_FLAGS per .cu file

  14. 14

    Using CMakes CHECK_CXX_COMPILER_FLAG with nvcc/cuda

  15. 15

    nvcc error, "no command" verifying installation of CUDA 10 on Debian 9 Stretch

  16. 16

    Python code ignoring if statements

  17. 17

    Code ignoring if statements - C++

  18. 18

    Code is ignoring IF command in C, Issues with FOR

  19. 19

    Why is the code ignoring one of the IF requirements?

  20. 20

    Code execution on CUDA/CPU

  21. 21

    optimizing CUDA code with branches

  22. 22

    optimizing CUDA code with branches

  23. 23

    CUDA : stencil code not working

  24. 24

    NVCC compilation options for generating the best code (using JIT)

  25. 25

    What should I do when (CUDA 7.5's) nvcc/cudafe++ crashes with a segfault?

  26. 26

    Can't get rid of "warning: command line option ‘-std=c++11’" using nvcc/CUDA/cmake

  27. 27

    After installing CUDA on Tegra Tx1 and sourcing the bashrc it will not find NVCC

  28. 28

    CUDA Segmentation fault in threads with no CUDA code

  29. 29

    visual studio code debuggin mocha is ignoring breakpoints

HotTag

Archive