title: ERROR: SYCL kernel cannot call through a function pointer, DPCPP, TBB
body: <p>I try to define an array of functions and pass to the map, which I defined as a class, then if my device is CPU, the execution of each of my functions over the vector goes through the CPU, if not, goes through the SYCL part and execute on GPU.
  At the same time, I want to measure the performance of my code, the performance of executing my code on CPU with TBB library.
  The problem is, when I compile my program it shows me this error and I do not know how can I fix it.
  I should point out that, before defining an array of functions, with definition of local copy of function in the SYCL part, my code works well and I had the result, but after defining an array of function, it troughs an error.
  my code:</p>
  <pre><code>    #include &lt;CL/sycl.hpp&gt;
  #include &lt;iostream&gt;
  #include &lt;tbb/tbb.h&gt;
  #include &lt;tbb/parallel_for.h&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;queue&gt;
  #include&lt;tbb/blocked_range.h&gt;
  #include &lt;tbb/global_control.h&gt;
  #include &lt;chrono&gt;
  
  
  using namespace tbb;
  
  template&lt;class Tin, class Tout, class Function&gt;
  class Map {
  private:
      Function fun;
  public:
      Map() {}
      Map(Function f):fun(f) {}
  
  
      std::vector&lt;Tout&gt; operator()(bool use_tbb, std::vector&lt;Tin&gt;&amp; v) {
          std::vector&lt;Tout&gt; r(v.size());
          if(use_tbb){
              // Start measuring time
              auto begin = std::chrono::high_resolution_clock::now();
              tbb::parallel_for(tbb::blocked_range&lt;Tin&gt;(0, v.size()),
                          [&amp;](tbb::blocked_range&lt;Tin&gt; t) {
                      for (int index = t.begin(); index &lt; t.end(); ++index){
                          r[index] = fun(v[index]);
                      }
              });
              // Stop measuring time and calculate the elapsed time
              auto end = std::chrono::high_resolution_clock::now();
              auto elapsed = std::chrono::duration_cast&lt;std::chrono::nanoseconds&gt;(end - begin);
              printf(&quot;Time measured: %.3f seconds.\n&quot;, elapsed.count() * 1e-9);
              return r;
           } else {
                  sycl::queue gpuQueue{sycl::gpu_selector()};
                  sycl::range&lt;1&gt; n_item{v.size()};
                  sycl::buffer&lt;Tin, 1&gt; in_buffer(&amp;v[0], n_item);
                  sycl::buffer&lt;Tout, 1&gt; out_buffer(&amp;r[0], n_item);
                  gpuQueue.submit([&amp;](sycl::handler&amp; h){
                      //local copy of fun
                      auto f = fun;
                      sycl::accessor in_accessor(in_buffer, h, sycl::read_only);
                      sycl::accessor out_accessor(out_buffer, h, sycl::write_only);
                      h.parallel_for(n_item, [=](sycl::id&lt;1&gt; index) {
                          out_accessor[index] = f(in_accessor[index]);
                      });
                  }).wait();
           }
                  return r;
      }
  };
  
  template&lt;class Tin, class Tout, class Function&gt;
  Map&lt;Tin, Tout, Function&gt; make_map(Function f) { return Map&lt;Tin, Tout, Function&gt;(f);}
  
  
  typedef int(*func)(int x);
  //define different functions
  auto function = [](int x){ return x; };
  auto functionTimesTwo = [](int x){ return (x*2); };
  auto functionDivideByTwo = [](int x){ return (x/2); };
  auto lambdaFunction = [](int x){return (++x);};
  
  int main(int argc, char *argv[]) {
  
      std::vector&lt;int&gt; v = {1,2,3,4,5,6,7,8,9};
  
      //Array of functions
      func functions[] =
          {
              function,
              functionTimesTwo,
              functionDivideByTwo,
              lambdaFunction
          };
      for(int i = 0; i&lt; sizeof(functions); i++){
          auto m1 = make_map&lt;int, int&gt;(functions[i]);
          std::vector&lt;int&gt; r = m1(true, v);
          //print the result
          for(auto &amp;e:r) {
              std::cout &lt;&lt; e &lt;&lt; &quot; &quot;;
           }
      }
      
  
    return 0;
  }
  </code></pre>
  <p>The ERROR:</p>
  <pre><code>SYCL kernel cannot call through a function pointer
  </code></pre>