CUDA 3.0 and cmake and emulation mode

I am trying to use CUDA with cmake (v 2.8) on my Mac (OSX 10.6). While this works fine, I created a small sample to try it out (see below). However, when I enable emulation mode, it can no longer invoke the CUDA core, and I get the following error message:

Cuda error: Kernel call: Invalid device function.

I also tried to compile it by calling nvcc manually and didn’t get an error, so I think it might be a cmake issue.

I also noticed that emulation mode was deprecated in CUDA 3.0. Why is this? Nvidia notes in their release notes that they provide Nexus for VS and cuda-gdb for Linux. But what about OSX? I couldn't find cuda-gdb on the OSX version installed here.?!

Below files

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project (test)

find_package(CUDA)
add_definitions(-Wall)

# Use CUDA emulator?
set(CUDA_BUILD_EMULATION ON)
set(CUDA_64_BIT_DEVICE_CODE OFF)    # Does not work on a Mac currently
set(CMAKE_C_FLAGS -m32)
set(CMAKE_CXX_FLAGS -m32)
set(CUDA_VERBOSE_BUILD ON)

include_directories("${PROJECT_BINARY_DIR}")

cuda_add_executable(test
    test.cu
)

      

test.cu

#include <cuda.h>
#include <stdlib.h>
#include <stdio.h>

#include "test_kernel.cu"

void checkCUDAError(const char *msg);

int main( int argc, const char** argv )
{
    int n = 3;
    float* a_h;
    a_h = (float *)malloc(sizeof(float)*n);
    float* a_d;
    cudaMalloc((void**) &a_d, sizeof(float)*n);

    hello<<<1,128>>>(a_d, n);
    checkCUDAError("kernel invocation");
    checkCUDAError("memcpy");

    free(a_h);
    cudaFree(a_d);

    return 0;
}

void checkCUDAError(const char *msg)
{
    cudaError_t err = cudaGetLastError();
    if( cudaSuccess != err)
    {
        fprintf(stderr, "Cuda error: %s: %s.\n", msg,
                cudaGetErrorString( err) );
        exit(EXIT_FAILURE);
    }
}

      

test_kernel.cu

#include <stdio.h>

__global__ void hello(float*a, int i)
{
    int j = i+1;
#ifdef _DEVICEEMU
    printf("Hello.\n");
#endif
}

      

+2


a source to share


1 answer


Cm



http://forums.nvidia.com/index.php?showtopic=166570&st=0&p=1043250&#entry1043250

+2


a source







All Articles