Git Product home page Git Product logo

darknet-on-opencl's Introduction

Darknet on OpenCL

Darknet

Darknet is an open source neural network framework written in C and CUDA.
It is fast, easy to install, and supports CPU and GPU computation.
You can find the origin project here.

Darknet on OpenCL

As the origin darknet project is written in CUDA, this project is to port
the darknet to OpenCL. Also, darknet is assumed to run on Linux and used
some POSIX C APIs, This project rewrite this with standard C++ libraries.
So that it could also run on Windows.

Dependency

OpenCL
Make sure you have OpenCL installed, and set environment variables OPENCL_SDK
point to your OpenCL installed path.
clBLAS
clBLAS is equivalent to cuBLAS, you can find the source code here
and compile it yourself.
or you can use binary library for Windows/Ubuntu x64 platform I have already provided
You can find clBLAS.lib/clBLAS.dll for Windows and libclBLAS.so for Linux
as well as header file here.

Build

Windows
This project is prepared with Visual Studio 2017, just open darknet_cl.sln
and build it.
To enable OpenCL, please set environment variables OPENCL_SDK first.
To enable OpenCV, please set environment variables OPENCV_INCLUDE_DIR
and OPENCV_LIB first.
Linux
mkdir build && cd build
cmake ../
make

Usage

Once you compiled this project, it has the same usage as darknet,
you can find it here.
If you compile the project depend on the clBLAS library I provided, you'd better
copy dependent library clBLAS.dll or libclBLAS.so to
system lib path.(C:\Windows\System32 or /usr/lib).

Attention

This project didn't build the DarkGo into the darknet_cl, maybe support it later.

darknet-on-opencl's People

Contributors

ganyc717 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

darknet-on-opencl's Issues

cmake found wrong opencl path

Hi,
i've installed intel opencl driver on ubuntu 16.04 following this link https://software.intel.com/en-us/articles/opencl-drivers#latest_linux_driver , the path of opencl lib is /opt/intel/opencl ,and when i ran clinfo , i got these outputs in first few lines :

Number of platforms 1
Platform Name Intel(R) OpenCL
Platform Vendor Intel(R) Corporation
Platform Version OpenCL 1.2
Platform Profile FULL_PROFILE
Platform Extensions cl_khr_3d_image_writes cl_khr_byte_addressable_store cl_khr_depth_images cl_khr_fp64 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_icd cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_spir
Platform Extensions function suffix INTEL
Platform Name Intel(R) OpenCL

and device info :

Device Name Intel(R) Celeron(R) CPU J3455 @ 1.50GHz
Device Vendor Intel(R) Corporation
Device Vendor ID 0x8086
Device Version OpenCL 1.2 (Build 475)
Driver Version 1.2.0.475
Device OpenCL C Version OpenCL C 1.2
Device Type CPU
Device Profile FULL_PROFILE

Device Name Intel(R) HD Graphics
Device Vendor Intel(R) Corporation
Device Vendor ID 0x8086
Device Version OpenCL 1.2
Driver Version r5.0.63503
Device OpenCL C Version OpenCL C 1.2
Device Type GPU
Device Profile FULL_PROFILE

but cmake ../ found the wrong version and path of opencl :

ubuntu@ubuntu-bitinvo:~/Darknet-On-OpenCL/build$ cmake ../
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for CL_VERSION_2_0
-- Looking for CL_VERSION_2_0 - found
-- Found OpenCL: /usr/lib/x86_64-linux-gnu/libOpenCL.so (found version "2.0")
-- Found OpenCV: /usr/local (found version "3.4.1")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/Darknet-On-OpenCL/build

run ./darknet detect ~/tiny_yolo_optimized/tiny-yolo-op_final.cfg ~/tiny_yolo_optimized/tiny-yolo-op_final.weights data/dog.jpg and the output is :

layer filters size input output
0 conv 16 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 16 0.150 BFLOPs
1 blas_kernels_1.cl build log:
1:81:45: warning: implicit conversion from integral type to floating point type for overloadable function might lead to ambiguity
float mhat = m[index] / (1.0 - pow(B1, t));
~~~ ^
1:82:45: warning: implicit conversion from integral type to floating point type for overloadable function might lead to ambiguity
float vhat = v[index] / (1.0 - pow(B2, t));
~~~ ^
1:189:55: warning: implicit conversion from integral type to floating point type for overloadable function might lead to ambiguity
variance[i] += pow((x[index] - mean[i]), 2);
~~~ ^
1:330:62: warning: implicit conversion from integral type to floating point type for overloadable function might lead to ambiguity
sum += (i+id < spatial) ? pow((x[index] - mean[filter]), 2) : 0;
~~~ ^
fcl build 1 succeeded.
bcl build succeeded.

max 2 x 2 / 2 416 x 416 x 16 -> 208 x 208 x 16
2 conv 32 3 x 3 / 1 208 x 208 x 16 -> 208 x 208 x 32 0.399 BFLOPs
3 max 2 x 2 / 2 208 x 208 x 32 -> 104 x 104 x 32
4 conv 64 3 x 3 / 1 104 x 104 x 32 -> 104 x 104 x 64 0.399 BFLOPs
5 max 2 x 2 / 2 104 x 104 x 64 -> 52 x 52 x 64
6 conv 128 3 x 3 / 1 52 x 52 x 64 -> 52 x 52 x 128 0.399 BFLOPs
7 max 2 x 2 / 2 52 x 52 x 128 -> 26 x 26 x 128
8 conv 256 3 x 3 / 1 26 x 26 x 128 -> 26 x 26 x 256 0.399 BFLOPs
9 max 2 x 2 / 2 26 x 26 x 256 -> 13 x 13 x 256
10 conv 512 3 x 3 / 1 13 x 13 x 256 -> 13 x 13 x 512 0.399 BFLOPs
11 conv 30 1 x 1 / 1 13 x 13 x 512 -> 13 x 13 x 30 0.005 BFLOPs
12 detection
mask_scale: Using default '1.000000'
Loading weights from /home/ubuntu/tiny_yolo_optimized/tiny-yolo-op_final.weights...Done!
im2col_kernels.cl build log:
2:36:18: warning: '/*' within block comment
//*data_col_ptr = data_im_ptr[ii * width + jj];
^
fcl build 1 succeeded.
bcl build succeeded.

activation_kernels.cl build log:
fcl build 1 succeeded.
bcl build succeeded.

maxpool_layer_kernels.cl build log:
fcl build 1 succeeded.
bcl build succeeded.

warning: Linking two modules of different data layouts: '' is 'e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024' whereas '' is 'e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32:64'

warning: Linking two modules of different target triples: ' is 'spir' whereas '' is 'vISA_32'

warning: Linking two modules of different data layouts: '' is 'e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024' whereas '' is 'e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32:64'

warning: Linking two modules of different target triples: ' is 'spir' whereas '' is 'vISA_32'

warning: Linking two modules of different data layouts: '' is 'e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024' whereas '' is 'e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32:64'

warning: Linking two modules of different target triples: ' is 'spir' whereas '' is 'vISA_32'

warning: Linking two modules of different data layouts: '' is 'e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024' whereas '' is 'e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32:64'

warning: Linking two modules of different target triples: ' is 'spir' whereas '' is 'vISA_32'

warning: Linking two modules of different data layouts: '' is 'e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024' whereas '' is 'e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32:64'

warning: Linking two modules of different target triples: ' is 'spir' whereas '' is 'vISA_32'

warning: Linking two modules of different data layouts: '' is 'e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024' whereas '' is 'e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32:64'

warning: Linking two modules of different target triples: ' is 'spir' whereas '' is 'vISA_32'

opencl execution error, code -11 -11
terminate called after throwing an instance of 'std::runtime_error'
what(): OpenCL error, code: -11
Aborted (core dumped)

Running this on FPGA

Hey, I am trying to optimize YOLOv3 architecture on fpga. I am planning to use a existing opencl implementation of yolov3 for this as a reference. I would like to know if I will be able to run this openCL implementation on FPGA ? If not what changes do I need to make ?

It would be a great help if you could give me your ideas.
Thanks in advance !

OpenCV not work

Hi @ganyc717
I want to run your code on the VS2015 and windows 7.
In mode with OPENCV, but this mode not working

  1. Not included headers for opencv in demo.cpp
  2. Not defined pthread_t is not defined in demo.cpp
    And other..

FPS slow down

Hi @ganyc717
I find one more problem. After run
darknet_cl.exe detector demo data/voc.data yolo-voc.cfg yolo-voc.weights test.mp4
On the first frames I get 7,1 FPS, but after several minutes I get less 5 FPS.

How to use it as a shared library?

I am trying to export is as a shared library by adding
add_library(darknet SHARED ${DIR_LIB_SRC})

Everything compile and link but I get weird unexpected results in the detections. Does anyone exported it before?
This is what I get using the original executable:
predictions

This is what I get using an executable from a different project which links the shared library:
predictions

Support for simrdwn project

There is another project The Satellite Imagery Multiscale Rapid Detection (simrdwn) which is based on extended work of yolt and yolt is extended work of yolo. Can you please add support for yolt? Or guide me through to get it working on OpenCL?

GPU to CPU copy speed bottleneck?

Hi,
Thanks for this awesome implementation. I would like to know how you are handling gpu to cpu optimization? are you using any special techniques to do this or just direct copying form gpu?
Thanks!!

clEnqueueNDRangeKernel NULL event_wait_list

Hello! i'm trying to build on Freebsd12 and very early in the compilation I get this error

-- Build files have been written to: /root/Darknet-On-OpenCL/build
root@jarvis:~/Darknet-On-OpenCL/build # make
[  1%] Building CXX object CMakeFiles/darknet.dir/darknet_cl/src/activation_kernels_cl.cpp.o
/root/Darknet-On-OpenCL/darknet_cl/src/activation_kernels_cl.cpp:31:17: error: no matching function for call to 'clEnqueueNDRangeKernel'
        cl_int error = clEnqueueNDRangeKernel(*cl->queue, kernel, 3, NULL, global_size, NULL, NULL, NULL, &e);
                       ^~~~~~~~~~~~~~~~~~~~~~

/usr/local/include/CL/cl.h:1293:1: note: candidate function not viable: no known conversion from 'nullptr_t' to 'cl_uint' (aka 'unsigned int') for 7th argument
clEnqueueNDRangeKernel(cl_command_queue /* command_queue */,

Any idea?

Compilation errors

Tried to build the project on x64, got 9 compilation errors. Looks like some functions were not implemented eg. get_yolo_detections and etc.. Could you pls advise and help? Thanks so much.

Errors:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "int __cdecl get_yolo_detections(struct layer,int,int,int,int,float,int *,int,struct detection *)" (?get_yolo_detections@@YAHUlayer@@HHHHMPEAHHPEAUdetection@@@z) referenced in function "void __cdecl fill_network_boxes(struct network *,int,int,float,float,int *,int,struct detection *)" (?fill_network_boxes@@YAXPEAUnetwork@@HHMMPEAHHPEAUdetection@@@z) darknet_cl C:\Personal\Project\Darknet-On-OpenCL\darknet_cl\network.obj 1

Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "int __cdecl yolo_num_detections(struct layer,float)" (?yolo_num_detections@@YAHUlayer@@m@Z) referenced in function "int __cdecl num_detections(struct network *,float)" (?num_detections@@YAHPEAUnetwork@@m@Z) darknet_cl C:\Personal\Project\Darknet-On-OpenCL\darknet_cl\network.obj 1

.
.
.

Linking CXX executable darknet issue

When I enter
make
It stops working at:
Linking CXX executable darknet

The output is:
../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const@GLIBCXX_3.4.21' ../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::operator=(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)@GLIBCXX_3.4.21'
../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char const*)@GLIBCXX_3.4.21' ../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::~basic_string()@GLIBCXX_3.4.21'
../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::c_str() const@GLIBCXX_3.4.21' ../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::basic_string(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)@GLIBCXX_3.4.21'
../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream(std::_Ios_Openmode)@GLIBCXX_3.4.21' ../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::append(char const*)@GLIBCXX_3.4.21'
../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_stringstream()@GLIBCXX_3.4.21' ../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::compare(char const*) const@GLIBCXX_3.4.21'
../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)@GLIBCXX_3.4.21' ../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::basic_string(char const*, std::allocator const&)@GLIBCXX_3.4.21'
../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::insert(unsigned long, char const*)@GLIBCXX_3.4.21' ../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::append(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)@GLIBCXX_3.4.21'
../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::str() const@GLIBCXX_3.4.21' ../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::operator=(std::__cxx11::basic_string<char, std::char_traits, std::allocator >&&)@GLIBCXX_3.4.21'
../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()@GLIBCXX_3.4.21' ../darknet_cl/clBLAS/libclBLAS.so: undefined reference to std::__cxx11::basic_string<char, std::char_traits, std::allocator >::compare(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) const@GLIBCXX_3.4.21'
../darknet_cl/clBLAS/libclBLAS.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits, std::allocator >::operator=(char const*)@GLIBCXX_3.4.21'
collect2: error: ld returned 1 exit status
make[2]: *** [darknet] Error 1
make[1]: *** [CMakeFiles/darknet.dir/all] Error 2
make: *** [all] Error 2

compile error: data.cpp

This is on OSX, using C++17:

/Darknet-On-OpenCL/darknet_cl/src/data.cpp:359:14: error: non-constant-expression cannot be
narrowed from type 'int' to 'float' in initializer list [-Wc++11-narrowing]
box b = {minx, miny, maxx-minx + 1, maxy-miny + 1};
^~~~
/Darknet-On-OpenCL/darknet_cl/src/data.cpp:359:14: note: insert an explicit cast to silence
this issue
box b = {minx, miny, maxx-minx + 1, maxy-miny + 1};
^~~~
static_cast( )
/Darknet-On-OpenCL/darknet_cl/src/data.cpp:359:20: error: non-constant-expression cannot be
narrowed from type 'int' to 'float' in initializer list [-Wc++11-narrowing]
box b = {minx, miny, maxx-minx + 1, maxy-miny + 1};
^~~~
/Users/harrison/Eio/Darknet-On-OpenCL/darknet_cl/src/data.cpp:359:20: note: insert an explicit cast to silence
this issue
box b = {minx, miny, maxx-minx + 1, maxy-miny + 1};
^~~~
static_cast( )
/Darknet-On-OpenCL/darknet_cl/src/data.cpp:359:26: error: non-constant-expression cannot be
narrowed from type 'int' to 'float' in initializer list [-Wc++11-narrowing]
box b = {minx, miny, maxx-minx + 1, maxy-miny + 1};
^~~~~~~~~~~~~
/Darknet-On-OpenCL/darknet_cl/src/data.cpp:359:26: note: insert an explicit cast to silence
this issue
box b = {minx, miny, maxx-minx + 1, maxy-miny + 1};
^~~~~~~~~~~~~
static_cast( )
/Users/harrison/Eio/Darknet-On-OpenCL/darknet_cl/src/data.cpp:359:41: error: non-constant-expression cannot be
narrowed from type 'int' to 'float' in initializer list [-Wc++11-narrowing]
box b = {minx, miny, maxx-minx + 1, maxy-miny + 1};
^~~~~~~~~~~~~
/Darknet-On-OpenCL/darknet_cl/src/data.cpp:359:41: note: insert an explicit cast to silence
this issue
box b = {minx, miny, maxx-minx + 1, maxy-miny + 1};
^~~~~~~~~~~~~
static_cast( )

OpenCL execution error, code -50

Branch: test-enable-shared-virtual-memory

Run > ./darknet detect cfg/yolov3-tiny.cfg weights/yolov3-tiny.weights data/dog.jpg

Error from https://github.com/ganyc717/Darknet-On-OpenCL/blob/test-enable-shared-virtual-memory/darknet_cl/src/blas_kernels_cl.cpp#L743

Backtrace:
#0 fill_gpu (N=, ALPHA=, X=..., INCX=)
at /Projects/Darknet-On-OpenCL-SVM/darknet_cl/src/blas_kernels_cl.cpp:740
#1 0x0000005555639118 in cl_make_array (x=, n=)
at /Projects/Darknet-On-OpenCL-SVM/darknet_cl/src/ocl.cpp:173
#2 0x0000005555632d9c in make_maxpool_layer (batch=, h=,
w=, c=, size=, stride=,
padding=)
at /Projects/Darknet-On-OpenCL-SVM/darknet_cl/src/maxpool_layer.cpp:47
#3 0x000000555563ca20 in parse_network_cfg (filename=)
at /Projects/Darknet-On-OpenCL-SVM/darknet_cl/src/parser.cpp:805
#4 0x0000005555633b90 in load_network (cfg=0x7fb48ceac0 "\004",
weights=0x7ffffff9b0 "weights/yolov3-tiny.weights", clear=0)
at /Projects/Darknet-On-OpenCL-SVM/darknet_cl/src/network.cpp:55

very slow on hd graphics 5000

Hi@ganyc717
Thank you for your project, I have tested on my intel hd graphics 5000, it is very slow, about 8 seconds for 1 single image, e.g, the dog.jpg
I have never modified your source code.

macOS/Windows support - CMakeLists.txt

In the CMakeLists.txt, instead of:

link_libraries(libpthread.so)

for compatibility with macOS and Windows use:

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
link_libraries(Threads::Threads)

Compile error in 12norm_layer.cpp

Hi

Awesome work :)

I'm getting an error while compiling, in 12norm_layer.cpp.

invalid conversion from int to LAYER_TYPE [-fpermissive] layer l = {0};

The error occurs on my raspberry running raspbian.

best regards

requires CUDA header files installation for AMD GPUs?

I get the following error:

$ cmake ..
CMake Warning (dev) in CMakeLists.txt:
  No project() command is present.  The top-level CMakeLists.txt file must
  contain a literal, direct call to the project() command.  Add a line of
  code such as

    project(ProjectName)

  near the top of the file, but after cmake_minimum_required().

  CMake is pretending there is a "project(Project)" command on the first
  line.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- The C compiler identification is Clang 13.0.0
-- The CXX compiler identification is Clang 13.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Looking for CL_VERSION_3_0
-- Looking for CL_VERSION_3_0 - found
-- Found OpenCL: /usr/local/lib/libOpenCL.so (found version "3.0") 
-- Found OpenCV: /usr/local (found version "4.6.0") 
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/home/user/Darknet-On-OpenCL/build
user@user:/usr/home/user/Darknet-On-OpenCL/build $ make -j8
[  1%] Building CXX object CMakeFiles/darknet.dir/darknet_cl/src/activation_kernels_cl.cpp.o
[  5%] Building CXX object CMakeFiles/darknet.dir/darknet_cl/src/activations.cpp.o
[  4%] Building CXX object CMakeFiles/darknet.dir/darknet_cl/src/avgpool_layer.cpp.o
[  2%] Building CXX object CMakeFiles/darknet.dir/darknet_cl/src/batchnorm_layer.cpp.o
[  6%] Building CXX object CMakeFiles/darknet.dir/darknet_cl/src/avgpool_layer_kernels_cl.cpp.o
[  8%] Building CXX object CMakeFiles/darknet.dir/darknet_cl/src/blas.cpp.o
[  9%] Building CXX object CMakeFiles/darknet.dir/darknet_cl/src/activation_layer.cpp.o
[ 11%] Building CXX object CMakeFiles/darknet.dir/darknet_cl/src/blas_kernels_cl.cpp.o
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/activation_kernels_cl.cpp:3:
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/ocl.h:4:
/usr/local/include/darknet.h:41:10: fatal error: 'cuda_runtime.h' file not found
#include <cuda_runtime.h>
         ^~~~~~~~~~~~~~~~
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/activations.cpp:1:
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/activations.h:3:
/usr/local/include/darknet.h:41:10: fatal error: 'cuda_runtime.h' file not found
#include <cuda_runtime.h>
         ^~~~~~~~~~~~~~~~
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/avgpool_layer_kernels_cl.cpp:3:
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/ocl.h:4:
/usr/local/include/darknet.h:41:10: fatal error: 'cuda_runtime.h' file not found
#include <cuda_runtime.h>
         ^~~~~~~~~~~~~~~~
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/batchnorm_layer.cpp:1:
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/activation_layer.cpp:1:
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/activation_layer.h:4:
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/activations.h:3:
/usr/local/include/darknet.h:41:10: fatal error: 'cuda_runtime.h' file not found
#include <cuda_runtime.h>
         ^~~~~~~~~~~~~~~~
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/convolutional_layer.h:4:
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/ocl.h:4:
/usr/local/include/darknet.h:41:10: fatal error: 'cuda_runtime.h' file not found
#include <cuda_runtime.h>
         ^~~~~~~~~~~~~~~~
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/blas.cpp:1:
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/blas.h:3:
/usr/local/include/darknet.h:41:10: fatal error: 'cuda_runtime.h' file not found
#include <cuda_runtime.h>
         ^~~~~~~~~~~~~~~~
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/blas_kernels_cl.cpp:3:
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/ocl.h:4:
/usr/local/include/darknet.h:41:10: fatal error: 'cuda_runtime.h' file not found
#include <cuda_runtime.h>
         ^~~~~~~~~~~~~~~~
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/avgpool_layer.cpp:1:
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/avgpool_layer.h:4:
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/image.h:9:
In file included from /usr/home/user/Darknet-On-OpenCL/darknet_cl/src/box.h:3:
/usr/local/include/darknet.h:41:10: fatal error: 'cuda_runtime.h' file not found
#include <cuda_runtime.h>
         ^~~~~~~~~~~~~~~~
1 error generated.
1 error generated.
--- CMakeFiles/darknet.dir/darknet_cl/src/activations.cpp.o ---
*** [CMakeFiles/darknet.dir/darknet_cl/src/activations.cpp.o] Error code 1

make[2]: stopped in /usr/home/user/Darknet-On-OpenCL/build
--- CMakeFiles/darknet.dir/darknet_cl/src/activation_layer.cpp.o ---
*** [CMakeFiles/darknet.dir/darknet_cl/src/activation_layer.cpp.o] Error code 1

make[2]: stopped in /usr/home/user/Darknet-On-OpenCL/build
1 error generated.
--- CMakeFiles/darknet.dir/darknet_cl/src/avgpool_layer.cpp.o ---
*** [CMakeFiles/darknet.dir/darknet_cl/src/avgpool_layer.cpp.o] Error code 1

make[2]: stopped in /usr/home/user/Darknet-On-OpenCL/build
1 error generated.
--- CMakeFiles/darknet.dir/darknet_cl/src/avgpool_layer_kernels_cl.cpp.o ---
*** [CMakeFiles/darknet.dir/darknet_cl/src/avgpool_layer_kernels_cl.cpp.o] Error code 1

make[2]: stopped in /usr/home/user/Darknet-On-OpenCL/build
1 error generated.
--- CMakeFiles/darknet.dir/darknet_cl/src/blas_kernels_cl.cpp.o ---
*** [CMakeFiles/darknet.dir/darknet_cl/src/blas_kernels_cl.cpp.o] Error code 1

make[2]: stopped in /usr/home/user/Darknet-On-OpenCL/build
1 error generated.
--- CMakeFiles/darknet.dir/darknet_cl/src/batchnorm_layer.cpp.o ---
*** [CMakeFiles/darknet.dir/darknet_cl/src/batchnorm_layer.cpp.o] Error code 1

make[2]: stopped in /usr/home/user/Darknet-On-OpenCL/build
1 error generated.
--- CMakeFiles/darknet.dir/darknet_cl/src/activation_kernels_cl.cpp.o ---
*** [CMakeFiles/darknet.dir/darknet_cl/src/activation_kernels_cl.cpp.o] Error code 1

make[2]: stopped in /usr/home/user/Darknet-On-OpenCL/build
1 error generated.
--- CMakeFiles/darknet.dir/darknet_cl/src/blas.cpp.o ---
*** [CMakeFiles/darknet.dir/darknet_cl/src/blas.cpp.o] Error code 1

make[2]: stopped in /usr/home/user/Darknet-On-OpenCL/build
8 errors

make[2]: stopped in /usr/home/user/Darknet-On-OpenCL/build
--- CMakeFiles/darknet.dir/all ---
*** [CMakeFiles/darknet.dir/all] Error code 2

make[1]: stopped in /usr/home/user/Darknet-On-OpenCL/build
1 error

make[1]: stopped in /usr/home/user/Darknet-On-OpenCL/build
*** [all] Error code 2

make: stopped in /usr/home/user/Darknet-On-OpenCL/build
1 error

make: stopped in /usr/home/user/Darknet-On-OpenCL/build

Using AMD GPU on FreeBSD 13.1

Thanks.

OpenCL error -13 on Ubuntu 14.04 and beignet

Used current clBLAS as the provided .so leads to many linker errors. darknet_cl compiles now but executing

build/darknet_cl detect cfg/yolo.cfg yolo.weights data/dog.jpg

leads to some warnings and -13:

31 detection
mask_scale: Using default '1.000000'
Beignet: "unable to find good values for local_work_size[i], please provide\n" " local_work_size[] explicitly, you can find good values with\n" " trial-and-error method."
Loading weights from yolo.weights...Done!
im2col_kernels.cl build log:
stringInput.cl:36:18: warning: '/*' within block comment

activation_kernels.cl build log:
stringInput.cl:21:12: warning: double precision constant requires cl_khr_fp64, casting to single precision

opencl execution error, code -13 -13
terminate called after throwing an instance of 'std::runtime_error'
what(): OpenCL error, code: -13
[1] 9856 abort (core dumped) build/darknet_cl detect cfg/yolo.cfg yolo.weights data/dog.jpg

ld: symbol(s) not found for architecture x86_64

Hello all! I'm using MacBook Air on M1 and try to run darknet on OpenCL.
I've installed OpenCL (version 1.2) and clBLAS using brew install.

This is what I get after cmake:

CMake Warning at CMakeLists.txt:9 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.

Could not find a package configuration file provided by "OpenCV" with any
of the following names:

OpenCVConfig.cmake
opencv-config.cmake

Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.

Despite it, the building goes successfully, but the compilation is not.
[100%] Linking CXX executable darknet
ld: warning: ignoring file ../darknet_cl/clBLAS/libclBLAS.so, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
Undefined symbols for architecture x86_64:
"_clblasSetup", referenced from:
CLWarpper::CLWarpper(int) in cl_warpper.cpp.o
CLWarpper::CLWarpper(int) in cl_warpper.cpp.o
CLWarpper::CLWarpper() in cl_warpper.cpp.o
CLWarpper::CLWarpper() in cl_warpper.cpp.o
CLWarpper::CLWarpper(_cl_platform_id*, _cl_device_id*) in cl_warpper.cpp.o
CLWarpper::CLWarpper(_cl_platform_id*, _cl_device_id*) in cl_warpper.cpp.o
CLWarpper::createForIndexedGpu(int) in cl_warpper.cpp.o
...
"_clblasSgemm", referenced from:
gemm_gpu(int, int, int, int, int, float, CLArray, int, CLArray, int, float, CLArray, int) in gemm.cpp.o
"_clblasTeardown", referenced from:
CLWarpper::~CLWarpper() in cl_warpper.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [darknet] Error 1
make[1]: *** [CMakeFiles/darknet.dir/all] Error 2
make: *** [all] Error 2

Could you please help me to solve this issue?

opencl execution error, code -11 -11

When I run
./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg

The output is this
loading weights from yolov3.weights...Done!
im2col_kernels.cl build log:
2:36:18: warning: '/*' within block comment
//*data_col_ptr = data_im_ptr[ii * width + jj];
^

opencl execution error, code -11 -11
terminate called after throwing an instance of 'std::runtime_error'
what(): OpenCL error, code: -11
Abortado (`core' generado)

couldn't open file: cfg/coco.data

I have pass building.
when I run,
./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg
system notify
couldn't open file: cfg/coco.data
How should I do?
Thank you very much.

macOS on M1: running make command generates 46 warnings and 9 errors

Hey all! Hope you can help me to solve my issues.
Basically, when I'm running make, here are the warnings that are generated:

/Users/User-PC/Darknet-On-OpenCL/darknet_cl/src/blas_kernels_cl.cpp:1161:96: warning: implicit conversion of NULL constant to 'cl_uint' (aka 'unsigned int') [-Wnull-conversion] cl_int status = clEnqueueNDRangeKernel(*cl->queue, kernel, 3, NULL, global_size, NULL, **NULL**, NULL, &e);

(it refers to the bolded NULL) they are all the same, but happen on different lines throughout the code
and here are the errors:

/Users/User-PC/Darknet-On-OpenCL/darknet_cl/src/blas_kernels_cl.cpp:333:27: error: non-constant-expression cannot be narrowed from type 'int' to 'size_t' (aka 'unsigned long') in initializer list [-Wc++11-narrowing] size_t global_size[] = { filters,BLOCK };

(it refers to filters) that also are repeating.
Do you have any clue what's wrong and how to solve it?
Thanks!

opencl execution error, code -6 -6

During training I got following error:

darknet_cl.exe detector train .\domino_training\obj.data .\cfg\yolov2-tiny-ocl.cfg .\domino_training\yolov2-tiny.conv.13

...

Region Avg IOU: 0.209439, Class: 0.002893, Obj: 0.260629, No Obj: 0.591567, Avg Recall: 0.000000, count: 20
opencl execution error, code -6 -6
0x00007FFC6496A839 (0xCCCCCCCCCCCCCCCC 0xCCCCCCCCCCCCCCCC 0xCCCCCCCCCCCCCCCC 0xCCCCCCCCCCCCCCCC), RaiseException() + 0x69 bytes(s)
0x00007FFC418A7ED7 (0x00000046B72F2908 0x00007FF6C076D5D0 0x00000046B72F2808 0xCCCCCCCCCCCCCCCC), _CxxThrowException() + 0x137 bytes(s)
0x00007FF6C06334E1 (0x00000046FFFFFFFA 0x0000000000000000 0x00000046B72F2A60 0x00000046B72F2E98), CLWarpper::checkError() + 0x191 bytes(s), c:\users\drozi\downloads\darknet-on-opencl-master\darknet_cl\src\cl_warpper.cpp, line 216 + 0x7A byte(s)
0x00007FF6C066F580 (0x00000046B72F5970 0x0000004600000020 0x0000000000000058 0x0000004600000058), im2col_gpu() + 0x440 bytes(s), c:\users\drozi\downloads\darknet-on-opencl-master\darknet_cl\src\im2col_kernels_cl.cpp, line 36
0x00007FF6C0640685 (0x00000046B72F87D0 0x00000046B72F9600 0xCCCCCCCCCCCCCCCC 0xCCCCCCCCCCCCCCCC), backward_convolutional_layer_gpu() + 0x5E5 bytes(s), c:\users\drozi\downloads\darknet-on-opencl-master\darknet_cl\src\convolutional_kernels_cl.cpp, line 244
0x00007FF6C06BD6B3 (0x000001C76E11E3E0 0xCCCCCCCCCCCCCCCC 0xCCCCCCCCCCCCCCCC 0xCCCCCCCCCCCCCCCC), backward_network_gpu() + 0x1E3 bytes(s), c:\users\drozi\downloads\darknet-on-opencl-master\darknet_cl\src\network.cpp, line 812 + 0x47 byte(s)
0x00007FF6C06BD285 (0x000001C76E11E3E0 0xCCCCCCCCCCCCCCCC 0xCCCCCCCCCCCCCCCC 0xCCCCCCCCCCCCCCCC), backward_network() + 0x75 bytes(s), c:\users\drozi\downloads\darknet-on-opencl-master\darknet_cl\src\network.cpp, line 269
0x00007FF6C06C3F39 (0x000001C76E11E3E0 0xCCCCCCCC0000000A 0xCCCCCCCC00000000 0x000001C747106070), train_network_datum() + 0x89 bytes(s), c:\users\drozi\downloads\darknet-on-opencl-master\darknet_cl\src\network.cpp, line 296
0x00007FF6C06C3E15 (0x000001C76E11E3E0 0x00000046B72FF3A0 0x00000046B72FD0E8 0x000000007FFE6000), train_network() + 0x115 bytes(s), c:\users\drozi\downloads\darknet-on-opencl-master\darknet_cl\src\network.cpp, line 325 + 0xC byte(s)
0x00007FF6C05E0A3B (0x000001C76C086BF6 0x000001C76C086C11 0x000001C76C086C2B 0x00000046B72FF6B4), train_detector() + 0x71B bytes(s), c:\users\drozi\downloads\darknet-on-opencl-master\darknet_cl\example\detector.cpp, line 120 + 0x2E byte(s)
0x00007FF6C05DF8D8 (0x00007FF600000006 0x000001C76C086BA0 0x00007FF6C070CF28 0xCCCCCCCC00000000), run_detector() + 0x548 bytes(s), c:\users\drozi\downloads\darknet-on-opencl-master\darknet_cl\example\detector.cpp, line 682 + 0x59 byte(s)
0x00007FF6C05DD774 (0x0000000000000006 0x000001C76C086BA0 0x0000000000000000 0x00007FF6C07079F8), main() + 0x204 bytes(s), c:\users\drozi\downloads\darknet-on-opencl-master\darknet_cl\example\darknet.cpp, line 434 + 0x12 byte(s)
0x00007FF6C06EF984 (0x00007FF6C0707000 0x00007FF6C07075B8 0x0000000000000000 0x0000000000000000), invoke_main() + 0x34 bytes(s), d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl, line 79
0x00007FF6C06EF86E (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000), __scrt_common_main_seh() + 0x12E bytes(s), d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl, line 288 + 0x5 byte(s)
0x00007FF6C06EF72E (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000), __scrt_common_main() + 0xE bytes(s), d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl, line 331
0x00007FF6C06EFA19 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000), mainCRTStartup() + 0x9 bytes(s), d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp, line 17
0x00007FFC66687BD4 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000), BaseThreadInitThunk() + 0x14 bytes(s)
0x00007FFC67A0CED1 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000), RtlUserThreadStart() + 0x21 bytes(s)

I am on Windows 10 Pro, Core i5 4200U (Intel HD 4000), got newest Open CL stuff from Intel website.
I tried it a couple of times and the error occurred everytime, only the amount of successful batches before the error differs.
I compiled the project in VS2017, without OpenCV.

macOS support

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.

Train support

Hi @ganyc717 again
When I run train mode in the begining of the train I get this error
Assertion failed: buffer.major != NULL, file src/ocl.cpp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.