Git Product home page Git Product logo

Comments (27)

battlesnake avatar battlesnake commented on August 18, 2024

I'm guessing that my OpenCL compiler/hardware doesn't support tanh

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

Yes.... that's two of you now... but looking at http://www.notebookcheck.net/AMD-Radeon-HD-8750M.87147.0.html seems this card supports OpenCL 1.2?

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

(Had a browse through the AMD drivers download, and came up with http://support.amd.com/en-us/download/desktop?os=Linux+x86_64 , but it didnt say what version of OpenCL these support... might be worth a shot though?)

(Edit: ah, per http://wiki.cchtml.com/index.php/Hardware , seems like maybe this driver doesnt support HD8750M? Kind of hard to tell...)

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

(Note that I'm pretty sure opencl 1.1 itself solidly supports tanh: https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/tan.html )

from deepcl.

battlesnake avatar battlesnake commented on August 18, 2024

I'm running the open-source driver, which could be why it is at v1.1

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

Ok. Maybe you can add in tanh :-) I think you can construct it as ( e^x - c^(-x) ) / ( e^x + e^(-x) ). Or... you could hack the DeepCL code to use this. In cl/activate.cl, simply replace tanh(output) with this expression.

from deepcl.

battlesnake avatar battlesnake commented on August 18, 2024

I know :) I'm just curious as to why the OpenCL compiler can't already do that - maybe I should submit a bug report for mesa

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

Well... I guess you could modify their code. But... I'm curious how this could be running on your GPU. It seems like Clover is compiling the opencl itself, and I doubt it's compiling into AMD ISA? (ie http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/07/AMD_GCN3_Instruction_Set_Architecture.pdf and so on ). So, seems like it might be running in software, on your CPU?

from deepcl.

battlesnake avatar battlesnake commented on August 18, 2024

Could be, although I'd be amazed if my Haswell + Intel's drivers couldn't handle tanh!

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

So, what I think is, Clover runs your OpenCL code, just like a script, like running something in Python and so on. I'm fairly sure that no OpenCL code is actually sent to your CPU, to run as Intel OpenCL.

OpenCL => Clover OpenCL Scripting engine => executes as normal x86 program, inside Clover

(Edit: I should have just used hte 'Edit' button really :-P Not sure why I didnt.... )

(Edit2: but I'm not really sure what Clover is doing. Scripting would sound too slow. But compiling to x86 on the fly would sound strange too. But compiling to AMD ISA seems unlikely. Soo... ????)

from deepcl.

battlesnake avatar battlesnake commented on August 18, 2024

You're right, Clover runs on CPU. Given this, I'm amazed that it doesn't support tanh...

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

:-)

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

Hi. Apparently I'm wrong. Clover does run on GPU :-) See Element-Research/rnn#41

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

So, what I'd suggest is, creating a fork/branch, and modifying activate.cl to write tanh in terms of exp. The expression for tanh in terms of exp is something like: (exp(y) - exp(-y)) / (exp(y) + exp(-y))

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

Note: you'd need to modify these lines basically: https://github.com/hughperkins/DeepCL/blob/master/cl/activate.cl#L10-L13

#ifdef TANH
    #define ACTIVATION_FUNCTION(output) (tanh(output))
#elif defined SCALEDTANH
    #define ACTIVATION_FUNCTION(output) (1.7159f * tanh(0.66667f * output))

I guess it will need to look something like (just doing it for TANH for now):

#ifdef TANH
    #define ACTIVATION_FUNCTION(output) ((exp(output) - exp(-output)) / (exp(output) + exp(-output)))

from deepcl.

wbernoudy avatar wbernoudy commented on August 18, 2024

I've been having the same issue with tanh on my system (R9 290 but with OpenCL 1.1). I would like to start messing around with what you've suggested hughperkins. However, editing the cl/activate.cl seems to do absolutely nothing, after make or after running the test Python script. After running the Python script, I still get:

Something went wrong with clCreateKernel, OpenCL erorr code -45
cl/activate.cl build log: 
input.cl:30:23: warning: implicit declaration of function 'tanh' is invalid in C99
input.cl:11:42: note: expanded from macro 'ACTIVATION_FUNCTION'
unsupported call to function tanh in activate
Traceback (most recent call last):
  File "test_deepcl.py", line 35, in <module>
    net, "rt2-8c5z-relu-mp2-16c5z-relu-mp3-150n-tanh-10n")
  File "NetDefToNet.pyx", line 7, in PyDeepCL.NetdefToNet.createNetFromNetdef (PyDeepCL.cxx:15006)
RuntimeError: 
kernel source:

It then repeats the original source of cl/activate.cl without any of my changes. I'm sure I'm missing something simple, but do you mind pointing out what I'm missing? How do I actually test my changes to cl/activate.cl?

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

You need to do one of two things, either:

  • obtain an OpenCL driver for your GPU that implements the tanh function, or
  • modify DeepCL to write tanh using exp function, which is fairly straightforward, see #35 (comment)

from deepcl.

wbernoudy avatar wbernoudy commented on August 18, 2024

Thanks for the quick reply! I'm trying to choose option 2 and modify DeepCL.

However, after I've modified cl/activate.cl by using the exp and compiled, my changes don't seem to matter. I get the same error and the build log error shows the previous source code. Does that make sense? What do I need to do to compile the changes I've made to cl/activate.cl?

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

You'll need to turn on cog during compilation. Basically, cd into build directory, run ccmake .., and set the configuration options something like:

deepclccmake

You wont see the COG option initially, but if you set MAINTAINER_OPTIONS to ON, and press c, it will appear :-)

I'd recommend you start by getting the non-python version working first, since it involves fewer compilation steps. You can test by running the unit tests ./deepcl_unittests, creating a new one if necessary, but I think you can use:

./deepcl_unittests tests=testactivationforward.comparespecific_0_1_activation3_small2_tanh

from deepcl.

wbernoudy avatar wbernoudy commented on August 18, 2024

Great! Took a little more troubleshooting but compiling is working and my changes are showing up.

Thanks again for the quick response and the wonderful project.

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

Awesome! Once you have that working, do you mind creating a fork/branch, so other people can use it too? (I'll probably take a copy of the fork too; and might ponder if there's a way of adding it into master somehow)

from deepcl.

wbernoudy avatar wbernoudy commented on August 18, 2024

I'm happy to do so. However, a few things to consider:

  1. I basically just added one line to the cl/activate.cl consisting of your suggestion. This then fixed the missing tanh problem, and I was finally able to pass the testactivationforward.comparespecific_0_1_activation3_small2_tanh unit test.
  2. However, I was still failing 49 of the unit tests (before the fix I was failing 50). This seems to be due to the another OpenCL 1.1 error, OpenCL does not support the 'static' storage class specifier.
  3. I randomly just got OpenCL 1.2 to work and now I am passing 100% of the unit tests.

Do you still think it's worth it for just this fix? If OpenCL 1.1 is a priority, it seems we might want to tackle the other issue as well...

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

Ah, so finally you've switched to OpenCL 1.2 for now? Concretely, this means you are using the AMD drivers, rather than the Clover drivers, is that right?

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

By the way, I dont think either of the issues (missing tanh and missing static support are actually OpenCL 1.1 issues, I think these are both specific to the the Clover implementation of OpenCL 1.1. Having said this, maybe we can create a fork like 'clover-compatibility', where we handle these two issues? You can start by creating this from your change '1.', and then someone can revert my static additions, to handle the clover issue with static support (probably just revert some of 022b6a3 approximately, or just go through the cl/*.cl files, and replace static with ``)

from deepcl.

wbernoudy avatar wbernoudy commented on August 18, 2024

Not exactly. Before I was using the Clover drivers for OpenCL 1.1. I was then trying to upgrade OpenCL and somehow managed to get the Intel driver for OpenCL 1.2. So all the tests were successful using the Intel driver and my i5.

I now finally got the AMD drivers working for my R9 290 with OpenCL 2.0. That is also passing all the unit tests.

So yes, it seems like it is just Clover. I created the PR: #60

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

For anyone else coming across this thread, please note that the clover compatibility fork is at: https://github.com/hughperkins/DeepCL/tree/clover-compatibility (or https://github.com/rhyzomatic/DeepCL/tree/clover-compatibility , depending on how you look at it)

from deepcl.

hughperkins avatar hughperkins commented on August 18, 2024

Added notes on this to README.md 8ac7b0f Closing this issue for now

from deepcl.

Related Issues (20)

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.