caffe icon indicating copy to clipboard operation
caffe copied to clipboard

Cuda kernel failed. Error: invalid device function

Open caijinlong opened this issue 12 years ago • 31 comments

I have some errors like this when running the code. How to handle those problems?

F0221 16:54:21.855986 11564 im2col.cu:49] Cuda kernel failed. Error: invalid device function *** Check failure stack trace: *** @ 0x7f2556cc1b4d google::LogMessage::Fail() @ 0x7f2556cc5b67 google::LogMessage::SendToLog() @ 0x7f2556cc39e9 google::LogMessage::Flush() @ 0x7f2556cc3ced google::LogMessageFatal::~LogMessageFatal() @ 0x463bf2 caffe::im2col_gpu<>() @ 0x452031 caffe::ConvolutionLayer<>::Forward_gpu() @ 0x41288f caffe::Layer<>::Forward() @ 0x41c9be caffe::ConvolutionLayerTest_TestSimpleConvolution_Test<>::TestBody() @ 0x43becd testing::internal::HandleExceptionsInMethodIfSupported<>() @ 0x42dab1 testing::Test::Run() @ 0x42db97 testing::TestInfo::Run() @ 0x42dcd7 testing::TestCase::Run() @ 0x432bdf testing::internal::UnitTestImpl::RunAllTests() @ 0x43ba7d testing::internal::HandleExceptionsInMethodIfSupported<>() @ 0x42d0da testing::UnitTest::Run() @ 0x40f774 main @ 0x318ae1ecdd (unknown) @ 0x40f4c9 (unknown) /bin/sh: line 1: 11564 Aborted (core dumped) $testbin 0

caijinlong avatar Feb 21 '14 09:02 caijinlong

You might not have the GPU correctly set up, since the kernel call is saying invalid device function.

Yangqing

On Fri, Feb 21, 2014 at 1:30 AM, caijinlong [email protected]:

I have some errors like this when running the code. How to handle those problems?

F0221 16:54:21.855986 11564 im2col.cu:49] Cuda kernel failed. Error: invalid device function *** Check failure stack trace: *** @ 0x7f2556cc1b4d google::LogMessage::Fail() @ 0x7f2556cc5b67 google::LogMessage::SendToLog() @ 0x7f2556cc39e9 google::LogMessage::Flush() @ 0x7f2556cc3ced google::LogMessageFatal::~LogMessageFatal() @ 0x463bf2 caffe::im2col_gpu<>() @ 0x452031 caffe::ConvolutionLayer<>::Forward_gpu() @ 0x41288f caffe::Layer<>::Forward() @ 0x41c9be caffe::ConvolutionLayerTest_TestSimpleConvolution_Test<>::TestBody() @ 0x43becd testing::internal::HandleExceptionsInMethodIfSupported<>() @ 0x42dab1 testing::Test::Run() @ 0x42db97 testing::TestInfo::Run() @ 0x42dcd7 testing::TestCase::Run() @ 0x432bdf testing::internal::UnitTestImpl::RunAllTests() @ 0x43ba7d testing::internal::HandleExceptionsInMethodIfSupported<>() @ 0x42d0da testing::UnitTest::Run() @ 0x40f774 main @ 0x318ae1ecdd (unknown) @ 0x40f4c9 (unknown) /bin/sh: line 1: 11564 Aborted (core dumped) $testbin 0

Reply to this email directly or view it on GitHubhttps://github.com/BVLC/caffe/issues/138 .

Yangqing avatar Feb 21 '14 23:02 Yangqing

Thanks Yangqing. The problem has been solved. It is GPU's setting.

Jinlong

caijinlong avatar Feb 22 '14 03:02 caijinlong

@caijinlong would you mind posting what GPU settings were causing the problem?

Or @Yangqing are there any features (e.g., compute mode, persistence mode) that I should be aware of when configuring the GPU?

I'm having the same issue running on a K20; any code that runs a kernel gives an "Invalid Device Function" error.

Thanks! Nick

nickjacob avatar Mar 10 '14 17:03 nickjacob

Can you run any CUDA demo, such as the NVIDIA-bundled samples? When in doubt, updating one's CUDA driver is worth a shot.

shelhamer avatar Mar 10 '14 17:03 shelhamer

I can run the samples included in cuda 5.5, and my driver is at 319.37 which from reading other issues on here seems to be correct? Here's the output of deviceQuery (I'm running a K20 on AWS so I don't get access to fan speed for example)

./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GRID K520"
  CUDA Driver Version / Runtime Version          5.5 / 5.5
  CUDA Capability Major/Minor version number:    3.0
  Total amount of global memory:                 4096 MBytes (4294770688 bytes)
  ( 8) Multiprocessors, (192) CUDA Cores/MP:     1536 CUDA Cores
  GPU Clock rate:                                797 MHz (0.80 GHz)
  Memory Clock rate:                             2500 Mhz
  Memory Bus Width:                              256-bit
  L2 Cache Size:                                 524288 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
  Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
  Run time limit on kernels:                     No
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Bus ID / PCI location ID:           0 / 3
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 5.5, CUDA Runtime Version = 5.5, NumDevs = 1, Device0 = GRID K520
Result = PASS

and this is the output of nvidia-smi -a:


==============NVSMI LOG==============

Timestamp                           : Mon Mar 10 08:41:44 2014
Driver Version                      : 319.37

Attached GPUs                       : 1
GPU 0000:00:03.0
    Product Name                    : GRID K520
    Display Mode                    : Disabled
    Display Active                  : Disabled
    Persistence Mode                : Disabled
    Accounting Mode                 : Disabled
    Accounting Mode Buffer Size     : 128
    Driver Model
        Current                     : N/A
        Pending                     : N/A
    Serial Number                   : N/A
    GPU UUID                        : GPU-f1f63fae-f245-3463-b8cd-2446df9fd1f3
    VBIOS Version                   : 80.04.D4.00.04
    Inforom Version
        Image Version               : N/A
        OEM Object                  : N/A
        ECC Object                  : N/A
        Power Management Object     : N/A
    GPU Operation Mode
        Current                     : N/A
        Pending                     : N/A
    PCI
        Bus                         : 0x00
        Device                      : 0x03
        Domain                      : 0x0000
        Device Id                   : 0x118A10DE
        Bus Id                      : 0000:00:03.0
        Sub System Id               : 0x101410DE
        GPU Link Info
            PCIe Generation
                Max                 : 3
                Current             : 3
            Link Width
                Max                 : 16x
                Current             : 16x
    Fan Speed                       : N/A
    Performance State               : P0
    Clocks Throttle Reasons         : N/A
    Memory Usage
        Total                       : 4095 MB
        Used                        : 9 MB
        Free                        : 4086 MB
    Compute Mode                    : Default
    Utilization
        Gpu                         : 0 %
        Memory                      : 0 %
    Ecc Mode
        Current                     : N/A
        Pending                     : N/A
    ECC Errors
        Volatile
            Single Bit            
                Device Memory       : N/A
                Register File       : N/A
                L1 Cache            : N/A
                L2 Cache            : N/A
                Texture Memory      : N/A
                Total               : N/A
            Double Bit            
                Device Memory       : N/A
                Register File       : N/A
                L1 Cache            : N/A
                L2 Cache            : N/A
                Texture Memory      : N/A
                Total               : N/A
        Aggregate
            Single Bit            
                Device Memory       : N/A
                Register File       : N/A
                L1 Cache            : N/A
                L2 Cache            : N/A
                Texture Memory      : N/A
                Total               : N/A
            Double Bit            
                Device Memory       : N/A
                Register File       : N/A
                L1 Cache            : N/A
                L2 Cache            : N/A
                Texture Memory      : N/A
                Total               : N/A
    Retired Pages
        Single Bit ECC              : N/A
        Double Bit ECC              : N/A
        Pending                     : N/A
    Temperature
        Gpu                         : 27 C
    Power Readings
        Power Management            : Supported
        Power Draw                  : 35.32 W
        Power Limit                 : 125.00 W
        Default Power Limit         : 125.00 W
        Enforced Power Limit        : 125.00 W
        Min Power Limit             : 85.00 W
        Max Power Limit             : 130.00 W
    Clocks
        Graphics                    : 797 MHz
        SM                          : 797 MHz
        Memory                      : 2500 MHz
    Applications Clocks
        Graphics                    : N/A
        Memory                      : N/A
    Default Applications Clocks
        Graphics                    : N/A
        Memory                      : N/A
    Max Clocks
        Graphics                    : 797 MHz
        SM                          : 797 MHz
        Memory                      : 2500 MHz
    Compute Processes               : None

Thanks so much for the help!

nickjacob avatar Mar 10 '14 17:03 nickjacob

Can you try the device_query included in caffe/tools ? It seems that you are using Grid K520 in AWS, never tried that, so no sure if this would be helpul http://techblog.netflix.com/2014/02/distributed-neural-networks-with-gpus.html

sguada avatar Mar 10 '14 17:03 sguada

Thanks - applying information in netflix blog, although I think most of their issues were from direct calls to the nvidia performance primitive library, and caffe for me is getting stuck on custom cuda kernel calls. This is the output of the caffe device_query. Really appreciate the help!

Device id:                     0
Major revision number:         3
Minor revision number:         0
Name:                          GRID K520
Total global memory:           4294770688
Total shared memory per block: 49152
Total registers per block:     65536
Warp size:                     32
Maximum memory pitch:          2147483647
Maximum threads per block:     1024
Maximum dimension of block:    1024, 1024, 64
Maximum dimension of grid:     2147483647, 65535, 65535
Clock rate:                    797000
Total constant memory:         65536
Texture alignment:             512
Concurrent copy and execution: Yes
Number of multiprocessors:     8
Kernel execution timeout:      No

nickjacob avatar Mar 10 '14 17:03 nickjacob

@caijinlong Hi, could you share some thoughts about GPU setting please? I had exactly the same error. But I can run cuda samples successfully. Have no idea how to solve this. Thank you!

ailzhang avatar May 05 '14 21:05 ailzhang

On my system (GeForce GTX 750 Ti) I could solve the error by modifying the Makefile.config by changing

CUDA_ARCH := -gencode arch=compute_20,code=sm_20
-gencode arch=compute_20,code=sm_21
-gencode arch=compute_30,code=sm_30
-gencode arch=compute_35,code=sm_35 into

CUDA_ARCH := -gencode arch=compute_20,code=sm_20
-gencode arch=compute_20,code=sm_21
-gencode arch=compute_30,code=sm_30
-gencode arch=compute_35,code=sm_35
-gencode arch=compute_50,code=sm_50

eendebakpt avatar Jun 03 '14 20:06 eendebakpt

@eendebakpt, Hi, could you tell me how to compute the capacity of GPU? I don't know how to add '-gencode arch=compute_50,code=sm_50' ?

zimenglan-sysu avatar Jun 11 '14 09:06 zimenglan-sysu

@caijinlong hi, i has some problem below:

Solver scaffolding done. I0611 18:38:49.181289 26648 solver.cpp:49] Solving XXXNet F0611 18:38:49.206163 26648 im2col.cu:54] Cuda kernel failed. Error: invalid device function *** Check failure stack trace: *** @ 0x7f7a643d8b7d google::LogMessage::Fail() @ 0x7f7a643dac7f google::LogMessage::SendToLog() @ 0x7f7a643d876c google::LogMessage::Flush() @ 0x7f7a643db51d google::LogMessageFatal::~LogMessageFatal() @ 0x45a59c caffe::im2col_gpu<>() @ 0x455857 caffe::ConvolutionLayer<>::Forward_gpu() @ 0x4325aa caffe::Net<>::ForwardPrefilled() @ 0x425568 caffe::Solver<>::Solve() @ 0x40e9b5 main @ 0x7f7a61d5076d (unknown) @ 0x41018d (unknown) Aborted (core dumped) Done.

how to handle this problem? thanks

zimenglan-sysu avatar Jun 11 '14 10:06 zimenglan-sysu

Hi, I even changed it to gencode arch=compute_50,code=sm_50 but even than i received this below error, can any body help in this regards? .... debug: (top_id, top_data_id, blob_id, feat_id)=0,119,0,119 [ FAILED ] PowerLayerTest/1.TestPowerGradientGPU, where TypeParam = double (1737 ms) [----------] 20 tests from PowerLayerTest/1 (5441 ms total)

[----------] 5 tests from ConcatLayerTest/1, where TypeParam = double [ RUN ] ConcatLayerTest/1.TestSetupNum [ OK ] ConcatLayerTest/1.TestSetupNum (0 ms) [ RUN ] ConcatLayerTest/1.TestGPUGradient [ OK ] ConcatLayerTest/1.TestGPUGradient (102 ms) [ RUN ] ConcatLayerTest/1.TestCPUGradient [ OK ] ConcatLayerTest/1.TestCPUGradient (48 ms) [ RUN ] ConcatLayerTest/1.TestSetupChannels [ OK ] ConcatLayerTest/1.TestSetupChannels (0 ms) [ RUN ] ConcatLayerTest/1.TestCPUNum [ OK ] ConcatLayerTest/1.TestCPUNum (0 ms) [----------] 5 tests from ConcatLayerTest/1 (150 ms total)

[----------] 3 tests from PaddingLayerUpgradeTest [ RUN ] PaddingLayerUpgradeTest.TestSimple [ OK ] PaddingLayerUpgradeTest.TestSimple (1 ms) [ RUN ] PaddingLayerUpgradeTest.TestTwoTops [ OK ] PaddingLayerUpgradeTest.TestTwoTops (1 ms) [ RUN ] PaddingLayerUpgradeTest.TestImageNet [ OK ] PaddingLayerUpgradeTest.TestImageNet (1 ms) [----------] 3 tests from PaddingLayerUpgradeTest (3 ms total)

[----------] 1 test from GaussianFillerTest/0, where TypeParam = float [ RUN ] GaussianFillerTest/0.TestFill [ OK ] GaussianFillerTest/0.TestFill (0 ms) [----------] 1 test from GaussianFillerTest/0 (0 ms total)

[----------] 4 tests from TanHLayerTest/1, where TypeParam = double [ RUN ] TanHLayerTest/1.TestGradientCPU [ OK ] TanHLayerTest/1.TestGradientCPU (3 ms) [ RUN ] TanHLayerTest/1.TestForwardGPU F0723 15:33:51.379904 10297 tanh_layer.cu:30] Check failed: error == cudaSuccess (8 vs. 0) invalid device function *** Check failure stack trace: *** @ 0x2b626d617b7d google::LogMessage::Fail() @ 0x2b626d619c7f google::LogMessage::SendToLog() @ 0x2b626d61776c google::LogMessage::Flush() @ 0x2b626d61a51d google::LogMessageFatal::~LogMessageFatal() @ 0x64092e caffe::TanHLayer<>::Forward_gpu() @ 0x48cd82 caffe::TanHLayerTest_TestForwardGPU_Test<>::TestBody() @ 0x58d25d testing::internal::HandleExceptionsInMethodIfSupported<>() @ 0x585081 testing::Test::Run() @ 0x585166 testing::TestInfo::Run() @ 0x5852a7 testing::TestCase::Run() @ 0x5855fe testing::internal::UnitTestImpl::RunAllTests() @ 0x58cddd testing::internal::HandleExceptionsInMethodIfSupported<>() @ 0x5846de testing::UnitTest::Run() @ 0x4434dd main @ 0x2b626f98b76d (unknown) @ 0x4481ad (unknown) make: *** [runtest] Aborted (core dumped)

ihsanafredi avatar Jul 23 '14 13:07 ihsanafredi

@eendebakpt Thank you, your anwser also helps me figure out another problem in Toolkit DeepNet

lireagan avatar Dec 20 '14 12:12 lireagan

@caijinlong could you share the solution? I have changed "Makefile.config" to gencode both arch=compute_50,code=sm_50 and arch=compute_50,code=sm_50
arch=compute_50,code=compute_50
but even than i received this below error, can any body help in this regards? [----------] 9 tests from ConvolutionLayerTest/1, where TypeParam = double [ RUN ] ConvolutionLayerTest/1.TestGPUGradient F1021 11:33:59.305110 3138 im2col.cu:54] Check failed: error == cudaSuccess (8 vs. 0) invalid device function *** Check failure stack trace: *** @ 0x2b8793543daa (unknown) @ 0x2b8793543ce4 (unknown) @ 0x2b87935436e6 (unknown) @ 0x2b8793546687 (unknown) @ 0x5f4e90 caffe::im2col_gpu<>() @ 0x5df0e3 caffe::ConvolutionLayer<>::Forward_gpu() @ 0x41b110 caffe::Layer<>::Forward() @ 0x4296ca caffe::GradientChecker<>::CheckGradientExhaustive() @ 0x476831 caffe::ConvolutionLayerTest_TestGPUGradient_Test<>::TestBody() @ 0x547a63 testing::internal::HandleExceptionsInMethodIfSupported<>() @ 0x53e547 testing::Test::Run() @ 0x53e5ee testing::TestInfo::Run() @ 0x53e6f5 testing::TestCase::Run() @ 0x541a38 testing::internal::UnitTestImpl::RunAllTests() @ 0x541cc7 testing::UnitTest::Run() @ 0x412ac0 main @ 0x2b8797095ec5 (unknown) @ 0x417d57 (unknown) @ (nil) (unknown) make: *** [runtest] Aborted (core dumped) could you help me figure this problem?

empty16 avatar Oct 21 '15 03:10 empty16

@ihsanafredi Have you figured out this problem ?

empty16 avatar Oct 21 '15 03:10 empty16

My GPU was old.

ihsanafredi avatar Nov 09 '15 14:11 ihsanafredi

i did a simple: rm -r ./build mkdir build cmake .. make

The problem was a changed GPU, Sources needed to be rebuild.

dragontas avatar Feb 17 '16 15:02 dragontas

I have solved the same problem. This problem occur when the version of cuda doesn't mach the caffe. Trick lies in the Makefile.config

# For CUDA < 6.0, comment the *_50 lines for compatibility.

CUDA_ARCH := -gencode arch=compute_20,code=sm_20
-gencode arch=compute_20,code=sm_21
-gencode arch=compute_30,code=sm_30
-gencode arch=compute_35,code=sm_35
-gencode arch=compute_50,code=sm_50
-gencode arch=compute_50,code=compute_50

if your cuda<6.0, then comment the last two lines.

hongzhenwang avatar Jul 28 '16 12:07 hongzhenwang

@dragontas ' solution worked for me as well.

Jumabek avatar Sep 07 '16 00:09 Jumabek

I'm running this error with

$ docker run -ti caffe:gpu caffe --version
libdc1394 error: Failed
caffe version 1.0.0-rc3

and

$ nvidia-smi
Tue Oct 25 15:08:35 2016       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 370.28                 Driver Version: 370.28                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 1080    Off  | 0000:01:00.0      On |                  N/A |
|  0%   48C    P8     7W / 200W |     62MiB /  8105MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 1080    Off  | 0000:02:00.0     Off |                  N/A |
|  0%   38C    P8     7W / 200W |      1MiB /  8113MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|    0      1241    G   /usr/lib/xorg/Xorg                              60MiB |
+-----------------------------------------------------------------------------+

and

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Sun_Sep__4_22:14:01_CDT_2016
Cuda compilation tools, release 8.0, V8.0.44

loretoparisi avatar Oct 25 '16 13:10 loretoparisi