1

I don't know OpenCL very much but I know C/C++ API requires programmer to provide OpenCL code as a string. But lately I discovered ArrayFire library that doesn't require string-code to invoke some calculations. I wondered how is it working (it is open source but the code is a bit confusing). Would it be possible to write parallel for with OpenCL backend that invokes any piece of compiled (x86 for example) code like following:

template <typename F>
void parallel_for(int starts, int ends, F task) //API
{ /*some OpenCL magic */ }
//...
parallel_for(0, 255, [&tab](int i){ tab[i] *= 0.7; } ); //using

PS: I know I am for 99% too optimistic

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Mariusz Jaskółka
  • 4,137
  • 2
  • 21
  • 47
  • 1
    https://github.com/arrayfire/arrayfire -- the source is freely available. Why not just read it? – talonmies Dec 28 '16 at 20:14
  • OpenCL 2.2 has support for kernels written in a subset of C++14. (without virtual functions, new/delete, exceptions, etc.) – tmlen Dec 29 '16 at 15:31

1 Answers1

2

You cannot really call C++ Host code from the device using standard OpenCL. You can use SYCL, the Khronos standard for single-source C++ programming. SYCL allows to compile C++ directly into device code without requiring the OpenCL strings. You can call any C++ function from inside a SYCL kernel (as long as the source code is available). SYCL.tech has more links and updated information.

Ruyk
  • 775
  • 5
  • 11