okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-141-intel' into f-14028f70a52cf

main
2.4 KiB45 linesraw
1// launch_cost: host time per submission on an in-order queue (empty-ish kernel), with and without queue profiling, and with
2// an event per submission.  If the prompt path's ~6 submissions per expert cost this much each, the 25k experts of a 4K
3// prompt are launch-bound.
4#include <sycl/sycl.hpp>
5#include <chrono>
6#include <cstdio>
7#include <cstdlib>
8#include <vector>
9
10template <class F>
11static double per_call_us(sycl::queue& q, int n, F&& f) {
12    for (int i = 0; i < 100; ++i) f(i);
13    q.wait();
14    const auto t0 = std::chrono::steady_clock::now();
15    for (int i = 0; i < n; ++i) f(i);
16    const double submit_us = std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - t0).count() / n;
17    q.wait();
18    const double total_us = std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - t0).count() / n;
19    std::printf("    host submit %.2f us/call, until done %.2f us/call\n", submit_us, total_us);
20    return submit_us;
21}
22
23int main(int argc, char** argv) {
24    const int n = argc > 1 ? std::atoi(argv[1]) : 20000;
25    for (int prof = 0; prof < 2; ++prof) {
26        sycl::queue q = prof ? sycl::queue{sycl::gpu_selector_v, {sycl::property::queue::in_order(), sycl::property::queue::enable_profiling()}}
27                             : sycl::queue{sycl::gpu_selector_v, {sycl::property::queue::in_order()}};
28        float* d = sycl::malloc_device<float>(1 << 20, q);
29        std::printf("queue profiling %s\n", prof ? "on" : "off");
30        std::printf("  tiny kernel, 1 work-group:\n");
31        per_call_us(q, n, [&](int) { q.parallel_for(sycl::nd_range<1>(256, 256), [=](sycl::nd_item<1> it) { d[it.get_global_id(0)] = 1.f; }); });
32        std::printf("  kernel of 4096 work-groups (1M items):\n");
33        per_call_us(q, n / 4, [&](int) { q.parallel_for(sycl::nd_range<1>(1 << 20, 256), [=](sycl::nd_item<1> it) { d[it.get_global_id(0)] += 1.f; }); });
34        std::printf("  tiny kernel, event kept:\n");
35        sycl::event e;
36        per_call_us(q, n, [&](int) { e = q.parallel_for(sycl::nd_range<1>(256, 256), [=](sycl::nd_item<1> it) { d[it.get_global_id(0)] = 1.f; }); });
37        std::printf("  submit_barrier(event) + tiny kernel:\n");
38        per_call_us(q, n, [&](int) {
39            q.ext_oneapi_submit_barrier({e});
40            e = q.parallel_for(sycl::nd_range<1>(256, 256), [=](sycl::nd_item<1> it) { d[it.get_global_id(0)] = 1.f; });
41        });
42        sycl::free(d, q);
43    }
44    return 0;
45}