Trouble compiling kernel

Hello, I want to compile the following kernel (file invertVectorElements.cu) for use it later in a jcuda program.

extern "C"
__global__ void invertVectorElements(float* vector, int n)
{
    int i = threadIdx.x;
    if (i < n)
    {
       vector** = 1.0f / vector**;
    }
}

The result of compilation is

>nvcc invertVectorElements.cu

invertVectorElements.cu
tmpxft_000004ec_00000000-3_invertVectorElements.cudafe1.gpu
tmpxft_000004ec_00000000-8_invertVectorElements.cudafe2.gpu
invertVectorElements.cu
tmpxft_000004ec_00000000-3_invertVectorElements.cudafe1.cpp
tmpxft_000004ec_00000000-14_invertVectorElements.ii
LIBCMT.lib(crt0.obj) : error LNK2019: símbolo externo _main sin resolver al que hace refrencia en la función ___tmainCRTStartup
a.exe : fatal error LNK1120: 1 externos sin resolver

What’s the problem? How can I solve this?
Thanks!

Hello

When you just call
nvcc kernelFile.cu
then it tries to compile this file into a real application (i.e. into a runnable EXE file). For this, a “main” function would be needed, which is not present in the kernel, of course.

You have to call
nvcc -cubin invertVectorElements.cu -o invertVectorElements.cubin
to compile only the kernel into a “cubin” file. This cubin file can then be loaded with the driver API, and the kernel can be executed.

bye
Marco

great thank you very much.

Now, I’m having the following problem.
I compile the .CU file, wich generates the .CUBIN file, but occurs an Exception when I try execute the Java program:

Exception in thread "main" jcuda.CudaException: CUDA_ERROR_INVALID_IMAGE
        at jcuda.driver.JCudaDriver.checkResult(JCudaDriver.java:170)
        at jcuda.driver.JCudaDriver.cuModuleLoad(JCudaDriver.java:1400)
        at samples.JCudaRuntimeDriverMixSample.main(JCudaRuntimeDriverMixSample.java:47)
Java Result: 1

Hello

Hm … I’m not sure at the moment, but you may try spcifying the “Compute Capability” of your card when compiling the CUBIN, like
nvcc -cubin -arch sm_21 kernelFile.cu -o kernelFile.cubin
for Compute Capability 2.1.

(Usually, omitting this flag does not result in an INVALID_IMAGE, but in an INVALID_SOURCE, but you may give it a try).

If it does not work: Are you still using the Kernel that you posted?

bye
Marco

I’ll either have to add this to the FAQ, or create examples about how to use PTX files instead of CUBIN files… -_-

Problem solved. Solution?

(Before, I’m working with a X64 machine)

Go into windows control panel, add/remove programs and select visual studio. Click desinstall or change, click Add or Remove features. Into Language Tools->Visual C++ select: X64 Compilers and Tools

The way of compile (generated automatically by Visual Studio):
nvcc -m64 -arch sm_11 -cubin kernel.cu -o kernel.cubin

Hey, great that you could solve it.

I was not aware that a lack of 64bit support in VS could cause such a problem. I’m rarely working on a 64bit machine, and can not remember a case where it was necessary to explicitly specify the -m64 parameter for a CUBIN file - I always omitted it, and it worked so far.

In any case, thanks for this hint :slight_smile: