使用sm_35编译时运行CUDA代码,但使用sm_30失败

时间:2015-07-15 19:33:26

标签: debugging cuda gpgpu word2vec

我拥有的GPU设备是GeForce GT 750M,我发现它是计算能力3.0。我下载了这里找到的CUDA代码:(https://github.com/fengChenHPC/word2vec_cbow。它的makefile有标志-arch = sm_35。

由于我的设备是计算能力3.0,我将标志更改为-arch = sm_30。它编译得很好,但是当我运行代码时,我收到以下错误:

word2vec.cu 449 : unspecified launch failure

word2vec.cu 449 : unspecified launch failure

它多次显示,因为有多个CPU线程启动CUDA内核。请注意,线程不使用不同的流来启动内核,因此内核启动都是有序的。

现在,当我让标志为,即-arch = sm_35时,代码运行正常。有人可以解释为什么当我设置标志以匹配我的设备时代码不会运行吗?

2 个答案:

答案 0 :(得分:2)

不幸的是,你的结论是代码在为sm_35编译时运行并在sm_30 GPU上运行是不正确的。罪魁祸首是:

void cbow_cuda(long window, long negative, float alpha, long sentence_length, 
               int *sen, long layer1_size, float *syn0, long hs, float *syn1, 
               float *expTable, int *vocab_codelen, char *vocab_code,
               int *vocab_point, int *table, long table_size, 
               long vocab_size, float *syn1neg){
    int blockSize = 256;
    int gridSize = (sentence_length)/(blockSize/32);
    size_t smsize = (blockSize/32)*(2*layer1_size+3)*sizeof(float);
//printf("sm size is %d\n", smsize);
//fflush(stdout);
    cbow_kernel<1><<<gridSize, blockSize, smsize>>>
                   (window, negative, alpha, sentence_length, sen,
                    layer1_size, syn0, syn1, expTable, vocab_codelen,
                    vocab_code, vocab_point, table, table_size,
                    vocab_size, syn1neg);
}

如果由于API错误检查不完整而导致内核启动失败,则此代码将无提示失败。如果为sm_35构建并在sm_30上运行,则内核启动会失败。如果您将该函数的代码更改为此(添加内核启动错误检查):

void cbow_cuda(long window, long negative, float alpha, long sentence_length, 
               int *sen, long layer1_size, float *syn0, long hs, float *syn1, 
               float *expTable, int *vocab_codelen, char *vocab_code,
               int *vocab_point, int *table, long table_size, 
               long vocab_size, float *syn1neg){
    int blockSize = 256;
    int gridSize = (sentence_length)/(blockSize/32);
    size_t smsize = (blockSize/32)*(2*layer1_size+3)*sizeof(float);
//printf("sm size is %d\n", smsize);
//fflush(stdout);
    cbow_kernel<1><<<gridSize, blockSize, smsize>>>
                   (window, negative, alpha, sentence_length, sen,
                    layer1_size, syn0, syn1, expTable, vocab_codelen,
                    vocab_code, vocab_point, table, table_size,
                    vocab_size, syn1neg);
    checkCUDAError( cudaPeekAtLastError() );
}

并为sm_35编译并运行它,你应该在sm_30设备上得到它:

~/cbow/word2vec_cbow$ make
nvcc word2vec.cu -o word2vec -O3 -Xcompiler -march=native -w  -Xptxas="-v" -arch=sm_35 -lineinfo
ptxas info    : 0 bytes gmem
ptxas info    : Compiling entry function '_Z11cbow_kernelILx1EEvllflPKilPVfS3_PKfS1_PKcS1_S1_llS3_' for 'sm_35'
ptxas info    : Function properties for _Z11cbow_kernelILx1EEvllflPKilPVfS3_PKfS1_PKcS1_S1_llS3_
    0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info    : Used 34 registers, 448 bytes cmem[0], 8 bytes cmem[2]

~/cbow/word2vec_cbow$ ./word2vec -train text8 -output vectors.bin -cbow 1 -size 200 -window 7 -negative 1 -hs 1 -sample 1e-3 -threads 1 -binary 1 -save-vocab voc #> out 2>&1
Starting training using file text8
Vocab size: 71290
Words in train file: 16718843
vocab size = 71290
cbow.cu 114 : invalid device function

即。内核启动失败,因为在应用程序的CUDA cubin有效负载中找不到相应的设备代码。这也回答了您earlier question关于此代码输出不正确的原因。当使用默认选项构建时,分析内核根本不会在您的硬件上运行。

如果我为sm_30构建此代码并在具有2gb内存(计算能力3.0)的GTX 670上运行它,我明白了:

~/cbow/word2vec_cbow$ make
nvcc word2vec.cu -o word2vec -O3 -Xcompiler -march=native -w  -Xptxas="-v" -arch=sm_30 -lineinfo
ptxas info    : 0 bytes gmem
ptxas info    : Compiling entry function '_Z11cbow_kernelILx1EEvllflPKilPVfS3_PKfS1_PKcS1_S1_llS3_' for 'sm_30'
ptxas info    : Function properties for _Z11cbow_kernelILx1EEvllflPKilPVfS3_PKfS1_PKcS1_S1_llS3_
    0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info    : Used 34 registers, 448 bytes cmem[0], 12 bytes cmem[2]

~/cbow/word2vec_cbow$ ./word2vec -train text8 -output vectors.bin -cbow 1 -size 200 -window 7 -negative 1 -hs 1 -sample 1e-3 -threads 1 -binary 1 -save-vocab voc #> out 2>&1
Starting training using file text8
Vocab size: 71290
Words in train file: 16718843
vocab size = 71290
Alpha: 0.000009  Progress: 100.00%  Words/thread/sec: 1217.45k

即。代码正确运行完成,没有任何错误。我无法告诉您为什么您无法在硬件上运行代码,因为我无法在硬件上重现您的错误。您需要自己进行一些调试才能找到原因。

答案 1 :(得分:-1)

由于此LINK显示没有GeForce GTX 750M。

你的要么是:

GeForce GTX 750 Ti

GeForce GTX 750

GeForce GT 750M

如果你的是前两个之一,那么你的GPU是基于Maxwell的,并且计算能力= 5.0。

否则,您的GPU基于Kepler,计算能力= 3.0。

如果你不确定你的GPU是什么,首先要通过从NVIDIA SAMPLE运行deviceQuery来弄明白。

相关问题