sdemyanov / ConvNet

Convolutional Neural Networks for Matlab for classification and segmentation, including Invariang Backpropagation (IBP) and Adversarial Training (AT) algorithms. Trained on GPU, require cuDNN v5.
240 stars 141 forks source link

Compiling GPU code #14

Closed mrgloom closed 9 years ago

mrgloom commented 9 years ago

I'm using VS2010, win7 x64,CUDA SDK 6.5 .

I change version of Windows SDK to 7.0A in mex_CUDA_win64.xml и vcvars64.bat

because of error :

compile(2) Building with 'Microsoft Visual C++ 2010'. MEX completed successfully. C++ object files created Verbose mode is on. ... Looking for compiler 'NVIDIA CUDA Compiler' ... ... Looking for environment variable 'VS100COMNTOOLS' ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\'). ... Looking for file 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\cl.exe' ...Yes. ... Looking for folder 'C:\Program Files (x86)\Microsoft Visual Studio 10.0' ...Yes. ... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0' InstallationFolder ...No. Did not find installed compiler 'NVIDIA CUDA Compiler'. Error using mex No supported compiler or SDK was found. For options, visit http://www.mathworks.com/support/compilers/R2014a/win64.

Error in compile (line 115) mex(mexfile, ['"' cudafiles '"'], ['"' cppfiles '"'], ...

and I get error in filter_acts.cu

Error using mex filter_acts.cu

G:/Matlab/ConvNet-master/c++/cuda/sources/filter_acts.cu(1201): error: more than one instance of overloaded function "sqrt" matches the argument list: function "sqrt(double)" function "sqrt(float)" function "sqrt(long double)" argument types are: (int) 1 error detected in the compilation of "C:/Users/user/AppData/Local/Temp/tmpxft_00000f28_00000000-11_filter_acts.compute_30.cpp1.ii".

Error in compile (line 115) mex(mexfile, ['"' cudafiles '"'], ['"' cppfiles '"'], ...

I changed line 1201 int filterSize = (int) sqrt(filterPixels); to int filterSize = (int) sqrt((double)filterPixels);

same in img_acts.cu and weight_acts.cu. and there are lot's of warnings about type conversion.

mrgloom commented 9 years ago

but still get another error

run('G:\Matlab\ConvNet-master\cnnexamples.m') gpu Epoch: 1 Error using cnntrain_mex Assertion Failed: CUDA function call failed![30] G:/Matlab/ConvNet-master/c++/cuda/sources/mat_gpu.cu:180

Error in cnntrain (line 10) [weights, trainerr] = cnntrain_mex(layers, weights_in, params, train_x, train_y);

Error in cnnexamples (line 77) [weights, trainerr] = cnntrain(layers, weights, params, train_x, train_y, funtype);

Error in run (line 63) evalin('caller', [script ';']);

sdemyanov commented 9 years ago

1) The error that you get are due to the old version of visual studio, that does not have implementations for sqrt(float), as it is supposed to be according to the c++ standard. I did not remove other type conversion warnings, I'll do it later.

2) This is the error of texture creation. I guess it might happen because of problems with compute capability or something. Try to recompile the code with the CC of your GPU card. You can specify it in mex_CUDA_win64.xml.

mrgloom commented 9 years ago

Tried to replace COMPFLAGS line to COMPFLAGS="-gencode arch=compute_20,code=sm_21 --compiler-options=/c,/GR,/W3,/EHs,/nologo,/MD"

also tried COMPFLAGS="-arch compute_20 --compiler-options=/c,/GR,/W3,/EHs,/nologo,/MD"

and

COMPFLAGS="--compiler-options=/c,/GR,/W3,/EHs,/nologo,/MD"

same result compiles ok, but fails at run and give same error.

I'm using gtx 460

gpuDevice()

ans =

CUDADevice with properties:

                  Name: 'GeForce GTX 460'
                 Index: 1
     ComputeCapability: '2.1'
        SupportsDouble: 1
         DriverVersion: 6.5000
        ToolkitVersion: 5.5000
    MaxThreadsPerBlock: 1024
      MaxShmemPerBlock: 49152
    MaxThreadBlockSize: [1024 1024 64]
           MaxGridSize: [65535 65535 65535]
             SIMDWidth: 32
           TotalMemory: 1.0737e+09
            FreeMemory: NaN
   MultiprocessorCount: 7
          ClockRateKHz: 1451000
           ComputeMode: 'Default'
  GPUOverlapsTransfers: 1
KernelExecutionTimeout: 1
      CanMapHostMemory: 1
       DeviceSupported: 1
        DeviceSelected: 0
sdemyanov commented 9 years ago

Probably the reason is described here: "The texture object API is only supported on devices of compute capability 3.0 or higher". However, texture usage is not obligative. You can go through the code, find the usage of function "getTextureObject" and remove the blocks where it is used. It should make the code slower, but at least it will work. I would update the code, but I don't currently have time for that.

mrgloom commented 9 years ago

also find this

Note: A Kepler-generation GPU with shader model capability 3.5 or greater is required to run this code. This includes the chips GK110 and GK114, which can be found on the GPUs Tesla K20, Tesla K20x, Tesla K40, GeForce Titan, and GeForce GTX 780, among others. Older GPUs, including GK104-based GPUs such as the Tesla K10 and GeForce 680, won't work.

here https://code.google.com/p/cuda-convnet2/wiki/Compiling