arrayfire icon indicating copy to clipboard operation
arrayfire copied to clipboard

SIGSEGV using OpenCL backend

Open andreabedini opened this issue 11 years ago • 21 comments

Hi there,

I downloaded and compiled ArrayFire but I get a SIGSEGV running any test or example that use the OpenCL backend.

~/c/a/build ❯❯❯ ./test/gfor_opencl                                                                                                                                                          Running main() from gtest_main.cc
[==========] Running 17 tests from 2 test cases.
[----------] Global test environment set-up.
[----------] 8 tests from GFOR
[ RUN      ] GFOR.Assign_Scalar_Span
[1]    3974 segmentation fault  ./test/gfor_opencl

Backtrace of the crashed thread

Thread 1 Crashed:: Dispatch queue: opencl_runtime
0   libclh.dylib                        0x00007fff9d8f62e6 cuiModuleUnloadEx + 102
1   libclh.dylib                        0x00007fff9d8f4f3e cuiModuleUnload + 14
2   com.apple.GeForceGLDriver           0x000012344030b7a2 0x123440000000 + 3192738
3   com.apple.GeForceGLDriver           0x000012344030db48 gldExecuteKernel + 379
4   com.apple.opencl                    0x00007fff8fee04a7 0x7fff8fedd000 + 13479
5   com.apple.opencl                    0x00007fff8fefd0da 0x7fff8fedd000 + 131290
6   com.apple.opencl                    0x00007fff8ff009cc 0x7fff8fedd000 + 145868
7   libdispatch.dylib                   0x00007fff919c8453 _dispatch_client_callout + 8
8   libdispatch.dylib                   0x00007fff919cd083 _dispatch_queue_drain + 754
9   libdispatch.dylib                   0x00007fff919d36c9 _dispatch_queue_invoke + 549
10  libdispatch.dylib                   0x00007fff919c8453 _dispatch_client_callout + 8
11  libdispatch.dylib                   0x00007fff919cc2e3 _dispatch_root_queue_drain + 1890
12  libdispatch.dylib                   0x00007fff919cbb48 _dispatch_worker_thread3 + 91
13  libsystem_pthread.dylib             0x00007fff99d834f2 _pthread_wqthread + 1129
14  libsystem_pthread.dylib             0x00007fff99d81375 start_wqthread + 13

Full backtrace at http://pastebin.com/yqsNyDe5

I looked around but I couldn't find any useful info. Happy to debug more if someone guides me.

edit: this is on OSX 10.11

andreabedini avatar Oct 12 '15 05:10 andreabedini

Can you tell us the hardware you are running on?

pavanky avatar Oct 12 '15 11:10 pavanky

thanks @pavanky

~/c/a/build ❯❯❯ ./examples/helloworld/helloworld_opencl                                                                                                                                    ArrayFire v3.1.2 (OpenCL, 64-bit Mac OSX, build 77128bb)
[0] APPLE   : GeForce GTX 775M 
A
[1]    66867 abort      ./examples/helloworld/helloworld_opencl

cuda and cpu backends work just fine.

andreabedini avatar Oct 13 '15 00:10 andreabedini

@umar456 Can you look into this?

pavanky avatar Oct 13 '15 05:10 pavanky

@andreabedini Sorry about not checking back. Is this still an issue.

pavanky avatar Apr 24 '16 09:04 pavanky

@pavanky : yes this is till an issue. This seems to be the issue that I see here https://github.com/arrayfire/arrayfire-rust/issues/60#issuecomment-214251484

Seems to be OpenCL on Nvidia on OSX

Process 17224 launched: './test/gfor_opencl' (x86_64)
Running main() from gtest_main.cc
[==========] Running 18 tests from 3 test cases.
[----------] Global test environment set-up.
[----------] 8 tests from GFOR
[ RUN      ] GFOR.Assign_Scalar_Span
Process 17224 stopped
* thread #6: tid = 0x444921, 0x00007fff9914c2d6 libclh.dylib`cuiModuleUnloadEx + 102, queue = 'opencl_runtime', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
    frame #0: 0x00007fff9914c2d6 libclh.dylib`cuiModuleUnloadEx + 102
libclh.dylib`cuiModuleUnloadEx:
->  0x7fff9914c2d6 <+102>: movq   0x10(%r15), %rdi
    0x7fff9914c2da <+106>: addq   $0x260, %rdi
    0x7fff9914c2e1 <+113>: xorl   %esi, %esi
    0x7fff9914c2e3 <+115>: xorl   %edx, %edx
(lldb) bt
* thread #6: tid = 0x444921, 0x00007fff9914c2d6 libclh.dylib`cuiModuleUnloadEx + 102, queue = 'opencl_runtime', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
  * frame #0: 0x00007fff9914c2d6 libclh.dylib`cuiModuleUnloadEx + 102
    frame #1: 0x00007fff9914af2e libclh.dylib`cuiModuleUnload + 14
    frame #2: 0x00007fff8d0383dd GeForceGLDriver`___lldb_unnamed_function11029$$GeForceGLDriver + 461
    frame #3: 0x00007fff8d03a8a1 GeForceGLDriver`gldExecuteKernel + 379
    frame #4: 0x00007fff85e674a7 OpenCL`___lldb_unnamed_function22$$OpenCL + 737
    frame #5: 0x00007fff85e840da OpenCL`___lldb_unnamed_function438$$OpenCL + 419
    frame #6: 0x00007fff85e879cc OpenCL`___lldb_unnamed_function475$$OpenCL + 306
    frame #7: 0x00007fff939c140b libdispatch.dylib`_dispatch_client_callout + 8
    frame #8: 0x00007fff939c603b libdispatch.dylib`_dispatch_queue_drain + 754
    frame #9: 0x00007fff939cc707 libdispatch.dylib`_dispatch_queue_invoke + 549
    frame #10: 0x00007fff939c140b libdispatch.dylib`_dispatch_client_callout + 8
    frame #11: 0x00007fff939c529b libdispatch.dylib`_dispatch_root_queue_drain + 1890
    frame #12: 0x00007fff939c4b00 libdispatch.dylib`_dispatch_worker_thread3 + 91
    frame #13: 0x00007fff8e33c4de libsystem_pthread.dylib`_pthread_wqthread + 1129
    frame #14: 0x00007fff8e33a341 libsystem_pthread.dylib`start_wqthread + 13

jramapuram avatar Apr 25 '16 17:04 jramapuram

Any update on this? Still an issue on 97e1666

jramapuram avatar May 18 '16 21:05 jramapuram

@jramapuram any chance you are using a GT 650M GPU ?

pavanky avatar May 18 '16 21:05 pavanky

Nope GT 750M

jramapuram avatar May 18 '16 21:05 jramapuram

OK we'll get on to it ASAP.

pavanky avatar May 18 '16 21:05 pavanky

Thanks very much! Let me know if you need anything tested

jramapuram avatar May 18 '16 21:05 jramapuram

Tested some in arrayfire. It looks like the queue may be getting messed up somehow. Not entirely sure how this is happening.

We noticed the following two scenarios:

  1. If enough kernels are launched, the failure happens if getQueue().finish() is called.

  2. Even when calling only one kernel from arrayfire, the issue can be reproduced at getQueue().enqueueReadBuffer() when printing the output.

pavanky avatar May 24 '16 21:05 pavanky

Not able to reproduce this in stand alone code used here so far: https://gist.github.com/mlloreda/8f078f4e53877957004feb1f2fc24664

pavanky avatar May 24 '16 21:05 pavanky

@pavanky : Hmm, maybe the best recourse is to git bisect this issue? This error was not prevalent in 3.0 as far as I remember as I did use CL on Nvidia.

jramapuram avatar May 24 '16 21:05 jramapuram

@jramapuram There's a similar issue on boost compute: https://github.com/boostorg/compute/issues/615

The error they are seeing is identical to what we are seeing. I think it may have been a driver update that broke this not an arrayfire update.

You could always try older version of arrayfire and see if it works.

pavanky avatar May 25 '16 00:05 pavanky

@pavanky : It works on 3.0 as stated. Just tried it:

➜  build git:(86426db) ✗ ./test/gfor_opencl
Running main() from gtest_main.cc
[==========] Running 8 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 8 tests from GFOR
[ RUN      ] GFOR.Assign_Scalar_Span
current opengl context is -------- 0x7fc67e0b4200
current opengl context is -------- 0x7fc67e0b4200
[       OK ] GFOR.Assign_Scalar_Span (759 ms)
[ RUN      ] GFOR.Assign_Scalar_Seq
[       OK ] GFOR.Assign_Scalar_Seq (0 ms)
[ RUN      ] GFOR.Inc_Scalar_Span
[       OK ] GFOR.Inc_Scalar_Span (38 ms)
[ RUN      ] GFOR.Inc_Scalar_Seq
[       OK ] GFOR.Inc_Scalar_Seq (2 ms)
[ RUN      ] GFOR.Assign_Array_Span
[       OK ] GFOR.Assign_Array_Span (94 ms)
[ RUN      ] GFOR.Assign_Array_Seq
[       OK ] GFOR.Assign_Array_Seq (45 ms)
[ RUN      ] GFOR.Inc_Array_Span
[       OK ] GFOR.Inc_Array_Span (51 ms)
[ RUN      ] GFOR.Inc_Array_Seq
[       OK ] GFOR.Inc_Array_Seq (9 ms)
[----------] 8 tests from GFOR (998 ms total)

[----------] Global test environment tear-down
[==========] 8 tests from 1 test case ran. (998 ms total)
[  PASSED  ] 8 tests.

Here is my cmake output:

➜  build git:(86426db) ✗ cmake .. -DBUILD_CUDA=ON -DBUILD_OPENCL=ON
-- Using Dynamic FreeImage Lib
-- Using FreeImage library /usr/local/lib/libfreeimage.dylib
-- Using Dynamic GLEWmx Lib
-- GLFW found!
-- Using Dynamic GLEWmx Lib
-- GLFW found!
-- Checking for [Accelerate]
-- CBLAS library found
-- Using CBLAS Library: /System/Library/Frameworks/Accelerate.framework
-- FFTW Found ? TRUE
-- FFTW Library: /usr/local/lib/libfftw3.dylib;/usr/local/lib/libfftw3f.dylib
-- Using Dynamic GLEWmx Lib
-- A library with BLAS API found.
-- A library with LAPACK API found.
-- Boost version: 1.55.0
-- Using LIBNVVM_HOME: /Developer/NVIDIA/CUDA-7.5/nvvm
-- CUDA cusolver library available in CUDA Version 7.5
-- A library with BLAS API found.
-- A library with LAPACK API found.
-- Boost version: 1.55.0
-- BoostCompute...
--   getting https://github.com/boostorg/compute/archive/79aa8f9086fdf6ef6db78e889de0273b0eb7bd19.tar.gz
--   validating /tmp/arrayfire/build/third_party/compute-79aa8f9086fdf6ef6db78e889de0273b0eb7bd19.tar.gz
--   extracting /tmp/arrayfire/build/third_party/compute-79aa8f9086fdf6ef6db78e889de0273b0eb7bd19.tar.gz
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/arrayfire/build

clFFT version:

Cloning into 'clFFT-external'...
Note: checking out '1597f0f35a644789c7ad77efe79014236cca2fab'.

jramapuram avatar May 25 '16 09:05 jramapuram

@jramapuram thank's that'll be helpful!

pavanky avatar May 25 '16 10:05 pavanky

@jramapuram Can you see the output of af::info() ? We changed the order in which GPUs appear sometime after 3.0. You might be running the test on the iris pro..

pavanky avatar May 25 '16 17:05 pavanky

@jramapuram ok I just had @mlloreda test 3.0 on his machine. It works because the default GPU is Iris Pro. If we sent the GPU to nvidia, then the test still fails on 3.0. It looks like an OSX update broke it.

pavanky avatar May 25 '16 17:05 pavanky

Ah nice, good catch.

jramapuram avatar May 25 '16 18:05 jramapuram

I am experiencing this issue on an NVIDIA GT 610 running Debian 8 64-bit using the arrayfire Rust wrapper. Before setting up the nvidia device I could run arrayfire 3.4 w/ OpenCL using my CPU. Arrayfire stopped working after I set up my gpu. I think the issue is with OpenCL 1.1, as both my GT 610 and @jramapuram GT 750M are opencl 1.1 cards.

I believe my issue is related to this stackoverflow post:

I suspect that you are using the cl.hpp header file from the AMD APP SDK? If that is the case then the problem is that the header file calls an OpenCL 1.2 function (can't remember which one) that is supplied by the AMD devices in your system but not by the Nvidia GPU. Your Nvidia GPU only supports OpenCL 1.1. The best solution I know is to use the header files for OpenCL 1.1 from the Khronos website.

I attempted to compile arrayfire from source using OpenCL 1.1 headers but I have not been successful yet. The steps I've taken are:

  1. Download OpenCL headers
TGT_DIR=/home/$USER/opencl-headers-1.1/include
mkdir -p "$TGT_DIR/CL"
cd "$TGT_DIR/CL"
wget https://raw.githubusercontent.com/KhronosGroup/OpenCL-Headers/opencl11/{opencl,cl_platform,cl,cl_ext,cl_gl,cl_gl_ext}.h
  1. Build Arrayfire from source
cd arrayfire3.4
git submodule init
git submodule update
mkdir build 
cd build
export CPATH="$TGT_DIR:$CPATH"
export OPENCL_INCLUDE_DIRS=$TGT_DIR

cmake .. -DBUILD_OPENCL=1 -DBUILD_EXAMPLES=0 -DOPENCL_INCLUDE_DIRS=$TGT_DIR
make -j4

While building I still see the message.

-- OPENCL_INCLUDE_DIRS: /opt/AMDAPPSDK-3.0/include
-- FindOpenCL searching for 64-bit libraries
-- FindOpenCL /opt/AMDAPPSDK-3.0/lib/x86_64/libOpenCL.so, /opt/AMDAPPSDK-3.0/include

I don't expect a fix for outdated hardware, I'm simply reporting my findings.

cjweigle avatar Oct 15 '16 00:10 cjweigle