okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
8f70a52cf
main
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 ) { 12for (int i = 0 ;i < 100 ;++ i )f (i ); 13q .wait (); 14const auto t0 = std::chrono::steady_clock::now (); 15for (int i = 0 ;i < n ;++ i )f (i ); 16const double submit_us = std::chrono::duration < double , std::micro > (std::chrono::steady_clock::now ()- t0 ).count () /n ; 17q .wait (); 18const 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 ); 20return submit_us ; 21} 22 23int main (int argc ,char ** argv ) { 24const int n = argc > 1 ? std::atoi (argv [1 ]) :20000 ; 25for (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 ()}}; 28float * 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" ); 31per_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" ); 33per_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 ; 36per_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" ); 38per_call_us (q ,n , [& ](int ) { 39q .ext_oneapi_submit_barrier ({e }); 40e = 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 } 44return 0 ; 45}