ganyc717 / Darknet-On-OpenCL

Darknet On OpenCL
MIT License
100 stars 44 forks source link

macOS support #5

Open OliverUrbann opened 6 years ago

OliverUrbann commented 6 years ago

I made some small changes to the code and now it compiles on macOS High Sierra. However, running seems to be a problem. Executing:

build/darknet_cl detector demo cfg/coco.data cfg/yolo.cfg yolo.weights

leads to:

Demo layer filters size input output 0 conv 32 3 x 3 / 1 608 x 608 x 3 -> 608 x 608 x 32 1 opencl execution error, code -11 -11 libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: OpenCL error, code: -11

I'm not an expert for OpenCL and maybe someone has an idea before I spend a lot of time investigating this.

victorv commented 6 years ago

-11 is CL_BUILD_PROGRAM _FAILURE

There must be an unsupported extension used to build a CL module from clBuildProgram. You can get more information by digging up which file caused the error and examining more detailed error data which should indicate the line and/or failure.

cansik commented 6 years ago

@OliverUrbann Could you describe your small changes? I am not able to build it at the moment, but I am trying to create a pull request which adds MacOS support (https://github.com/cansik/Darknet-On-OpenCL).

Currently I have following problem at the end of the make process:

2 warnings generated.
[ 88%] Building CXX object CMakeFiles/darknet_cl.dir/darknet_cl/example/lsd.cpp.o
[ 89%] Building CXX object CMakeFiles/darknet_cl.dir/darknet_cl/example/nightmare.cpp.o
[ 91%] Building CXX object CMakeFiles/darknet_cl.dir/darknet_cl/example/regressor.cpp.o
[ 92%] Building CXX object CMakeFiles/darknet_cl.dir/darknet_cl/example/rnn.cpp.o
[ 94%] Building CXX object CMakeFiles/darknet_cl.dir/darknet_cl/example/segmenter.cpp.o
[ 95%] Building CXX object CMakeFiles/darknet_cl.dir/darknet_cl/example/super.cpp.o
[ 97%] Building CXX object CMakeFiles/darknet_cl.dir/darknet_cl/example/tag.cpp.o
[ 98%] Building CXX object CMakeFiles/darknet_cl.dir/darknet_cl/example/yolo.cpp.o
[100%] Linking CXX executable darknet_cl
ld: library not found for -llibpthread.so
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [darknet_cl] Error 1
make[1]: *** [CMakeFiles/darknet_cl.dir/all] Error 2
make: *** [all] Error 2
cansik commented 6 years ago

Ok I could build it now but I have the same error for the following command:

./darknet detect yolov2.cfg yolov2.weights data/dog.jpg
layer     filters    size              input                output
    0 conv     32  3 x 3 / 1   416 x 416 x   3   ->   416 x 416 x  32
    1 opencl execution error, code -11 -11
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: OpenCL error, code: -11
Abort trap: 6

@victorv Could you give us a hint how to check which extension is missing?

Is it maybe the problem that Apple is only supporting OpenCL 1.2?

-- Looking for CL_VERSION_1_2
-- Looking for CL_VERSION_1_2 - found
victorv commented 6 years ago

The error trap: 6 is a sig abort so you will need to run it with the debugger and figure out where the c++ library is aborting.

OliverUrbann commented 6 years ago

To be honest I lost interest in the port as I noticed that macOS supports OpenCL but not for the integrated GPU (at least on my system), only for CPU.

cansik commented 6 years ago

Debugged the executable with lldb:

(lldb) r detect yolov2.cfg yolov2.weights data/dog.jpg
Process 9247 launched: '/Users/cansik/git/private/Darknet-On-OpenCL/darknet' (x86_64)
2018-04-09 11:17:59.273556+0200 darknet[9247:3375726] MessageTracer: Falling back to default whitelist
layer     filters    size              input                output
    0 conv     32  3 x 3 / 1   416 x 416 x   3   ->   416 x 416 x  32
    1 opencl execution error, code -11 -11
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: OpenCL error, code: -11
Process 9247 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00007fff7a832b6e libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill:
->  0x7fff7a832b6e <+10>: jae    0x7fff7a832b78            ; <+20>
    0x7fff7a832b70 <+12>: movq   %rax, %rdi
    0x7fff7a832b73 <+15>: jmp    0x7fff7a829b00            ; cerror_nocancel
    0x7fff7a832b78 <+20>: retq   
Target 0: (darknet) stopped.
ganyc717 commented 6 years ago

Hi @cansik I have no Mac on my hand so no idea to debug, but today I run this on a platform which only support OpenCL 1.1 and have the same problem. I have pushed a patch and you can check whether it helps.

cansik commented 6 years ago

@ganyc717 Thank you, I tried it but it is still the same error. I think will buy an NVIDIA card together with an eGPU ;)

cansik commented 6 years ago

Could it be a problem that we are using clang version 9.1? Because on macs with an NVIDIA Graphic Card and CUDA installed, I had to downgrade the developer tools to build darkent.

Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Update: Nope, doesn't make a difference.

cansik commented 6 years ago

With the newest master release (1dd549bb54d3bf1f235904bc09f54a2cc2b42974) it is possible to run the network and load the model, but there are still errors.

./darknet detect yolov2.cfg yolov2.weights data/dog.jpg
layer     filters    size              input                output
    0 conv     32  3 x 3 / 1   416 x 416 x   3   ->   416 x 416 x  32  0.299 BFLOPs
    1 blas_kernels_1.cl build log:
<program source>:11:12: warning: comparison of integers of different signs: 'size_t' (aka 'unsignedlong') and 'int'
        if(offset < size) output[global_z*size + offset] *= biases[filter];
    ~~~~~~ ^ ~~~~
<program source>:223:10: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int'
    if(i < N) Y[OFFY+i*INCY] += ALPHA*X[OFFX+i*INCX];
       ~ ^ ~
<program source>:250:10: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int'
    if(i < N) {
       ~ ^ ~
<program source>:261:10: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int'
    if(i < N) X[i*INCX] += ALPHA;
       ~ ^ ~
<program source>:270:10: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int'
    if(i < N) X[i*INCX] *= ALPHA;
       ~ ^ ~
<program source>:279:7: warning: comparison of integers of different signs: 'size_t' (aka 'unsignedlong') and 'int'
        if(i < N) X[i*INCX] = ALPHA;
    ~ ^ ~
<program source>:294:10: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int'
    if(i < N) Y[i*INCY] *= X[i*INCX];
       ~ ^ ~

max          2 x 2 / 2   416 x 416 x  32   ->   208 x 208 x  32
    2 conv     64  3 x 3 / 1   208 x 208 x  32   ->   208 x 208 x  64  1.595 BFLOPs
    3 max          2 x 2 / 2   208 x 208 x  64   ->   104 x 104 x  64
    4 conv    128  3 x 3 / 1   104 x 104 x  64   ->   104 x 104 x 128  1.595 BFLOPs
    5 conv     64  1 x 1 / 1   104 x 104 x 128   ->   104 x 104 x  64  0.177 BFLOPs
    6 conv    128  3 x 3 / 1   104 x 104 x  64   ->   104 x 104 x 128  1.595 BFLOPs
    7 max          2 x 2 / 2   104 x 104 x 128   ->    52 x  52 x 128
    8 conv    256  3 x 3 / 1    52 x  52 x 128   ->    52 x  52 x 256  1.595 BFLOPs
    9 conv    128  1 x 1 / 1    52 x  52 x 256   ->    52 x  52 x 128  0.177 BFLOPs
   10 conv    256  3 x 3 / 1    52 x  52 x 128   ->    52 x  52 x 256  1.595 BFLOPs
   11 max          2 x 2 / 2    52 x  52 x 256   ->    26 x  26 x 256
   12 conv    512  3 x 3 / 1    26 x  26 x 256   ->    26 x  26 x 512  1.595 BFLOPs
   13 conv    256  1 x 1 / 1    26 x  26 x 512   ->    26 x  26 x 256  0.177 BFLOPs
   14 conv    512  3 x 3 / 1    26 x  26 x 256   ->    26 x  26 x 512  1.595 BFLOPs
   15 conv    256  1 x 1 / 1    26 x  26 x 512   ->    26 x  26 x 256  0.177 BFLOPs
   16 conv    512  3 x 3 / 1    26 x  26 x 256   ->    26 x  26 x 512  1.595 BFLOPs
   17 max          2 x 2 / 2    26 x  26 x 512   ->    13 x  13 x 512
   18 conv   1024  3 x 3 / 1    13 x  13 x 512   ->    13 x  13 x1024  1.595 BFLOPs
   19 conv    512  1 x 1 / 1    13 x  13 x1024   ->    13 x  13 x 512  0.177 BFLOPs
   20 conv   1024  3 x 3 / 1    13 x  13 x 512   ->    13 x  13 x1024  1.595 BFLOPs
   21 conv    512  1 x 1 / 1    13 x  13 x1024   ->    13 x  13 x 512  0.177 BFLOPs
   22 conv   1024  3 x 3 / 1    13 x  13 x 512   ->    13 x  13 x1024  1.595 BFLOPs
   23 conv   1024  3 x 3 / 1    13 x  13 x1024   ->    13 x  13 x1024  3.190 BFLOPs
   24 conv   1024  3 x 3 / 1    13 x  13 x1024   ->    13 x  13 x1024  3.190 BFLOPs
   25 route  16
   26 conv     64  1 x 1 / 1    26 x  26 x 512   ->    26 x  26 x  64  0.044 BFLOPs
   27 reorg              / 2    26 x  26 x  64   ->    13 x  13 x 256
   28 route  27 24
   29 conv   1024  3 x 3 / 1    13 x  13 x1280   ->    13 x  13 x1024  3.987 BFLOPs
   30 conv    425  1 x 1 / 1    13 x  13 x1024   ->    13 x  13 x 425  0.147 BFLOPs
   31 detection
mask_scale: Using default '1.000000'
Loading weights from yolov2.weights...Done!
im2col_kernels.cl build log:
<program source>:36:18: warning: '/*' within block comment
                //*data_col_ptr = data_im_ptr[ii * width + jj];
                 ^

activation_kernels.cl build log:
<program source>:11:7: warning: no previous prototype for function 'lhtan_activate_kernel'
float lhtan_activate_kernel(float x)
      ^
<program source>:18:7: warning: no previous prototype for function 'lhtan_gradient_kernel'
float lhtan_gradient_kernel(float x)
      ^
<program source>:24:7: warning: no previous prototype for function 'hardtan_activate_kernel'
float hardtan_activate_kernel(float x)
      ^
<program source>:30:7: warning: no previous prototype for function 'linear_activate_kernel'
float linear_activate_kernel(float x){return x;}
      ^
<program source>:31:7: warning: no previous prototype for function 'logistic_activate_kernel'
float logistic_activate_kernel(float x){return 1.f/(1.f + exp(-x));}
      ^
<program source>:32:7: warning: no previous prototype for function 'loggy_activate_kernel'
float loggy_activate_kernel(float x){return 2.f/(1.f + exp(-x)) - 1;}
      ^
<program source>:33:7: warning: no previous prototype for function 'relu_activate_kernel'
float relu_activate_kernel(float x){return x*(x>0);}
      ^
<program source>:34:7: warning: no previous prototype for function 'elu_activate_kernel'
float elu_activate_kernel(float x){return (x >= 0)*x + (x < 0)*(exp(x)-1);}
      ^
<program source>:35:7: warning: no previous prototype for function 'relie_activate_kernel'
float relie_activate_kernel(float x){return (x>0) ? x : .01f*x;}
      ^
<program source>:36:7: warning: no previous prototype for function 'ramp_activate_kernel'
float ramp_activate_kernel(float x){return x*(x>0)+.1f*x;}
      ^
<program source>:37:7: warning: no previous prototype for function 'leaky_activate_kernel'
float leaky_activate_kernel(float x){return (x>0) ? x : .1f*x;}
      ^
<program source>:38:7: warning: no previous prototype for function 'tanh_activate_kernel'
float tanh_activate_kernel(float x){return (2.f/(1 + exp(-2*x)) - 1);}
      ^
<program source>:39:7: warning: no previous prototype for function 'plse_activate_kernel'
float plse_activate_kernel(float x)
      ^
<program source>:46:7: warning: no previous prototype for function 'stair_activate_kernel'
float stair_activate_kernel(float x)
      ^
<program source>:54:7: warning: no previous prototype for function 'hardtan_gradient_kernel'
float hardtan_gradient_kernel(float x)
      ^
<program source>:59:7: warning: no previous prototype for function 'linear_gradient_kernel'
float linear_gradient_kernel(float x){return 1;}
      ^
<program source>:60:7: warning: no previous prototype for function 'logistic_gradient_kernel'
float logistic_gradient_kernel(float x){return (1-x)*x;}
      ^
<program source>:61:7: warning: no previous prototype for function 'loggy_gradient_kernel'
float loggy_gradient_kernel(float x)
      ^
<program source>:67:7: warning: no previous prototype for function 'relu_gradient_kernel'
float relu_gradient_kernel(float x){return (x>0);}
      ^
<program source>:68:7: warning: no previous prototype for function 'elu_gradient_kernel'
float elu_gradient_kernel(float x){return (x >= 0) + (x < 0)*(x + 1);}
      ^
<program source>:69:7: warning: no previous prototype for function 'relie_gradient_kernel'
float relie_gradient_kernel(float x){return (x>0) ? 1 : .01f;}
      ^
<program source>:70:7: warning: no previous prototype for function 'ramp_gradient_kernel'
float ramp_gradient_kernel(float x){return (x>0)+.1f;}
      ^
<program source>:71:7: warning: no previous prototype for function 'leaky_gradient_kernel'
float leaky_gradient_kernel(float x){return (x>0) ? 1 : .1f;}
      ^
<program source>:72:7: warning: no previous prototype for function 'tanh_gradient_kernel'
float tanh_gradient_kernel(float x){return 1-x*x;}
      ^
<program source>:73:7: warning: no previous prototype for function 'plse_gradient_kernel'
float plse_gradient_kernel(float x){return (x < 0 || x > 1) ? .01f : .125f;}
      ^
<program source>:74:7: warning: no previous prototype for function 'stair_gradient_kernel'
float stair_gradient_kernel(float x)
      ^
<program source>:80:7: warning: no previous prototype for function 'activate_kernel'
float activate_kernel(float x, int a)
      ^
<program source>:113:7: warning: no previous prototype for function 'gradient_kernel'
float gradient_kernel(float x, int a)
      ^

opencl execution error, code -11 -11
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: OpenCL error, code: -11
Abort trap: 6