<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Re:Quick random number on SYCL device in Intel® oneAPI DPC++/C++ Compiler</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1268252#M1044</link>
    <description>&lt;P&gt;Thanks &lt;a href="https://community.intel.com/t5/user/viewprofilepage/user-id/114694"&gt;@Alina_S_Intel&lt;/a&gt;! That's pretty much what I was looking for.&lt;/P&gt;</description>
    <pubDate>Fri, 26 Mar 2021 18:39:49 GMT</pubDate>
    <dc:creator>danielarndt</dc:creator>
    <dc:date>2021-03-26T18:39:49Z</dc:date>
    <item>
      <title>Quick random number on SYCL device</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1262724#M1006</link>
      <description>&lt;P&gt;I need a random value in kernels preferably by just reading some hardware counters. For CUDA I would simply use clock64(). Is there something similar I could use with Intel GPUs using SYCL?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 13:50:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1262724#M1006</guid>
      <dc:creator>danielarndt</dc:creator>
      <dc:date>2021-03-09T13:50:17Z</dc:date>
    </item>
    <item>
      <title>Re:Quick random number on SYCL device</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1263050#M1010</link>
      <description>&lt;P&gt;Hi Daniel,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks for reaching out to us.&lt;/P&gt;&lt;P&gt;There are multiple ways to implement the random number generation in your DPCPP code. Depending on the use-case you can either generate the random number inside your kernel or you can pass the randomly generated values to the kernel.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Based on the requirement you can choose different engines and can use their output to generate various random sequences(using different distributions).&lt;/P&gt;&lt;P&gt;Please refer to the below link for in-depth details of the random number generation usage using oneAPI DPC++ and oneDPL library.&lt;/P&gt;&lt;P&gt;&lt;A href="https://software.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-library-guide/top/random-number-generator.html" target="_blank"&gt;https://software.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-library-guide/top/random-number-generator.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;You can also use Intel oneMKL Library to generate random numbers, for more details please refer to the below link for oneMKL RNG model usage.&lt;/P&gt;&lt;P&gt;&lt;A href="https://software.intel.com/content/www/us/en/develop/documentation/oneapi-mkl-dpcpp-developer-reference/top/random-number-generators/intel-onemkl-rng-usage-model.html" target="_blank"&gt;https://software.intel.com/content/www/us/en/develop/documentation/oneapi-mkl-dpcpp-developer-reference/top/random-number-generators/intel-onemkl-rng-usage-model.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;You can choose any of the random number generators depending on your use-case.&lt;/P&gt;&lt;P&gt;Hope the provided details will help to solve your issues.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Warm Regards,&lt;/P&gt;&lt;P&gt;Abhishek&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Mar 2021 12:30:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1263050#M1010</guid>
      <dc:creator>AbhishekD_Intel</dc:creator>
      <dc:date>2021-03-10T12:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Re:Quick random number on SYCL device</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1263116#M1011</link>
      <description>&lt;P&gt;Hi Abhishek,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your response. Unfortunately, using the random generators in oneDPL or oneMKL doesn't really seem to fit my use case.&lt;/P&gt;
&lt;P&gt;What I need/want is rather an entropy source on the device so that concurrently running threads obtain significantly different values. The generated distribution doesn't need to be particularly elaborate. Also generating these values on the host is not really an option since I&amp;nbsp; don't control the invocation of the device function (and don't even have access to the sycl::item ideally).&lt;/P&gt;
&lt;P&gt;Hence, my question still is if there is a way to access any hardware counter that fulfills this purpose on the device (using assembly or intrinsics would be fine, in the worst case also just for Intel GPUs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 16:33:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1263116#M1011</guid>
      <dc:creator>danielarndt</dc:creator>
      <dc:date>2021-03-10T16:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Quick random number on SYCL device</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1264396#M1015</link>
      <description>&lt;P&gt;Hi Daniel,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the details.&amp;nbsp;Here is a way to achieve this kind of scenario you are looking for. You can generate some random seeds on the CPU based on the randomness you want and can pass that seed value to the kernel. Then you can feed this seed value and the offset of the threads to the random number engines for generating thread-safe, significantly random, and kind of unpredictable random numbers using different random generation functions inside your kernel. &lt;BR /&gt;Please refer to the below code snippet for more insight.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;sycl::queue queue(sycl::default_selector{});

    std::int64_t nsamples = 20;

    //generating seed value;
    auto now = std::chrono::system_clock::now();
    std::uint32_t seed = std::chrono::duration_cast&amp;lt;std::chrono::milliseconds&amp;gt;(now.time_since_epoch()).count();

    std::vector&amp;lt;float&amp;gt; x(nsamples);
    {
        sycl::buffer&amp;lt;float, 1&amp;gt; x_buf(x.data(), sycl::range&amp;lt;1&amp;gt;(x.size()));

        queue.submit([&amp;amp;] (sycl::handler &amp;amp;cgh) {

            auto x_acc =
            x_buf.template get_access&amp;lt;sycl::access::mode::write&amp;gt;(cgh);

            cgh.parallel_for&amp;lt;class count_kernel&amp;gt;(sycl::range&amp;lt;1&amp;gt;(nsamples),
                [=](sycl::item&amp;lt;1&amp;gt; idx) {
                std::uint64_t offset = idx.get_linear_id();
                // Create minstd_rand engine (use any engine)
                oneapi::dpl::minstd_rand engine(seed, offset);

                // Create float uniform_real_distribution distribution (use any distribution)
                oneapi::dpl::uniform_real_distribution&amp;lt;float&amp;gt; distr;

                // Generate random number
                auto res = distr(engine);

                // Use results from "res"
                ....
            });
        });
    }
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Intel is yet to come up with a dedicated function for hardware that will act as a counter for you to generate unpredictable random numbers.&lt;/P&gt;
&lt;P&gt;Hope this will help you to generate the randomness according to your use-case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warm Regards,&lt;/P&gt;
&lt;P&gt;Abhishek&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 14:14:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1264396#M1015</guid>
      <dc:creator>AbhishekD_Intel</dc:creator>
      <dc:date>2021-03-15T14:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: Quick random number on SYCL device</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1264482#M1017</link>
      <description>&lt;P&gt;Abhishek,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your answer and the code snippet. Unfortunately, I don't have direct access to the call site and can't generate anything on the host to copy over (with a reasonable amount of changes to the framework to be fitted). I would be happy about any DPC++ extensions going in the direction of my use case. &lt;LI-EMOJI id="lia_slightly-smiling-face" title=":slightly_smiling_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/P&gt;
&lt;P&gt;The actual use case is to manage resources specific to each running thread. For now, a simple compare exchange with a lock array always starting from the same guess is good enough (although slow due to contention).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 17:13:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1264482#M1017</guid>
      <dc:creator>danielarndt</dc:creator>
      <dc:date>2021-03-15T17:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: Quick random number on SYCL device</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1264791#M1027</link>
      <description>&lt;P&gt;Hi Daniel,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the details. We are working on it and we will get back to you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-Abhishek&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Mar 2021 11:22:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1264791#M1027</guid>
      <dc:creator>AbhishekD_Intel</dc:creator>
      <dc:date>2021-03-22T11:22:21Z</dc:date>
    </item>
    <item>
      <title>Re:Quick random number on SYCL device</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1268181#M1043</link>
      <description>&lt;P&gt;Thank you for your patience while we were preparing the answer to your question. &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;There is an OpenCL built-in intrinsic &lt;SPAN style="font-family: tahoma;"&gt;intel_get_cycle_counter. Y&lt;/SPAN&gt;ou can use it inside your GPU kernels to get the GPU execution unit timestamp.  For more information, please refer to &lt;A href="https://github.com/intel/pti-gpu/blob/master/chapters/binary_instrumentation/OpenCLBuiltIn.md" target="_blank"&gt;https://github.com/intel/pti-gpu/blob/master/chapters/binary_instrumentation/OpenCLBuiltIn.md&lt;/A&gt;  &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;#include &amp;lt;CL/sycl.hpp&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;using namespace sycl;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;typedef unsigned long ulong;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;#ifdef __SYCL_DEVICE_ONLY__&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;extern SYCL_EXTERNAL ulong __attribute__((overloadable)) intel_get_cycle_counter( void );&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;#endif&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;int main() {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;&amp;nbsp;queue q(gpu_selector{});&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;&amp;nbsp;std::cout &amp;lt;&amp;lt; "Device : " &amp;lt;&amp;lt; q.get_device().get_info&amp;lt;info::device::name&amp;gt;() &amp;lt;&amp;lt; std::endl;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;&amp;nbsp;q.submit([&amp;amp;](handler &amp;amp;h) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;  auto out = stream(1024, 768, h);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;  h.parallel_for(range&amp;lt;1&amp;gt;(100000), [=](auto i) {&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;   out &amp;lt;&amp;lt; "intel_get_cycle_counter: ";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;   #ifdef __SYCL_DEVICE_ONLY__&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;    ulong cycle_counter = intel_get_cycle_counter();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;    out &amp;lt;&amp;lt; cycle_counter &amp;lt;&amp;lt; endl;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;   #endif&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt; &amp;nbsp;});&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;&amp;nbsp;}).wait();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;&amp;nbsp;std::cout &amp;lt;&amp;lt; "Done" &amp;lt;&amp;lt; std::endl;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;&amp;nbsp;return 0;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 26 Mar 2021 14:08:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1268181#M1043</guid>
      <dc:creator>Alina_S_Intel</dc:creator>
      <dc:date>2021-03-26T14:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: Re:Quick random number on SYCL device</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1268252#M1044</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.intel.com/t5/user/viewprofilepage/user-id/114694"&gt;@Alina_S_Intel&lt;/a&gt;! That's pretty much what I was looking for.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 18:39:49 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1268252#M1044</guid>
      <dc:creator>danielarndt</dc:creator>
      <dc:date>2021-03-26T18:39:49Z</dc:date>
    </item>
    <item>
      <title>Re:Quick random number on SYCL device</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1286934#M1264</link>
      <description>&lt;P&gt;We will no longer respond to this thread.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 03 Jun 2021 16:12:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Quick-random-number-on-SYCL-device/m-p/1286934#M1264</guid>
      <dc:creator>Alina_S_Intel</dc:creator>
      <dc:date>2021-06-03T16:12:06Z</dc:date>
    </item>
  </channel>
</rss>

