okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
83cde2ca3
main
1// esimd_dpas_probe (151-b70): the DPAS peak an ESIMD kernel reaches on one device, registers only. 2// esimd_dpas_probe [reps=4096] [threads=8192] 3// Modes: fp16 (8x16x16, fp32 acc), s8 (8x16x32, int32 acc). RC=8 rows per DPAS, MT row tiles x NT column tiles of 4// accumulators per hardware thread; the A/B operands are loaded once (random bits), so the loop is pure DPAS. 5// Build: icpx -fsycl -fsycl-targets=intel_gpu_bmg_g31 -O3 esimd_dpas_probe.cpp 6#include <sycl/sycl.hpp> 7#include <sycl/ext/intel/esimd.hpp> 8#include <sycl/ext/intel/experimental/grf_size_properties.hpp> 9#include <chrono> 10#include <cstdio> 11#include <cstdlib> 12#include <vector> 13 14using namespace sycl::ext::intel::esimd ; 15namespace xmx= sycl::ext::intel::esimd::xmx; 16 17template < bool S8 ,int MT ,int NT ,int GRF > 18double run (sycl::queue & q ,int reps ,int threads ,uint32_t * src ,float * out ) { 19constexpr int KW = S8 ?8 :8 ;// dwords per row of A (K=32 s8 / K=16 fp16: 8 dwords) 20constexpr auto PA = S8 ? xmx::dpas_argument_type::s8 : xmx::dpas_argument_type::fp16 ; 21using CT = std::conditional_t < S8 ,int ,float > ; 22auto props = sycl::ext::oneapi::experimental::properties {sycl::ext::intel::experimental::grf_size < GRF > }; 23auto t0 = std::chrono::steady_clock::now (); 24q .submit ([& ](sycl::handler & h ) { 25h .parallel_for (sycl::nd_range < 1 > (threads ,8 ),props , [= ](sycl::nd_item < 1 > it )SYCL_ESIMD_KERNEL { 26const int tid = it .get_global_id (0 ); 27simd < int ,8 * KW > a [MT ]; 28simd < int ,16 * KW > b [NT ]; 29simd < CT ,128 > acc [MT ][NT ]; 30for (int i = 0 ;i < MT ;++ i )a [i ]= simd < int ,8 * KW > (0x3c003c00u + i * 0x01010101 + tid ,1 ); 31for (int j = 0 ;j < NT ;++ j )b [j ]= simd < int ,16 * KW > (0x3c003c00u + j * 0x00010001 ,1 ); 32for (int i = 0 ;i < MT ;++ i )for (int j = 0 ;j < NT ;++ j )acc [i ][j ]= 0 ; 33for (int r = 0 ;r < reps ;++ r ) { 34#pragma unroll 35for (int i = 0 ;i < MT ;++ i ) 36#pragma unroll 37for (int j = 0 ;j < NT ;++ j ) 38acc [i ][j ]= xmx::dpas < 8 ,8 ,CT ,CT ,int ,int ,PA ,PA > (acc [i ][j ],b [j ],a [i ]); 39 } 40float s = 0 ; 41for (int i = 0 ;i < MT ;++ i )for (int j = 0 ;j < NT ;++ j ) {simd < float ,128 > f = acc [i ][j ];s += reduce < float > (f , std::plus <> ()); } 42out [tid ]= s ; 43 }); 44 }).wait (); 45return std::chrono::duration < double > (std::chrono::steady_clock::now ()- t0 ).count (); 46} 47 48int main (int argc ,char ** argv ) { 49int reps = argc > 1 ?atoi (argv [1 ]) :4096 ,threads = argc > 2 ?atoi (argv [2 ]) :8192 ; 50 sycl::queue q {sycl::gpu_selector_v , sycl::property::queue::in_order ()}; 51 std::printf ("device %s\n" ,q .get_device ().get_info < sycl::info::device::name > ().c_str ()); 52float * out = sycl::malloc_device < float > (threads ,q ); 53uint32_t * src = nullptr ; 54auto rep = [& ](const char * nm ,double (* fn )(sycl::queue & ,int ,int ,uint32_t * ,float * ),int mt ,int nt ,bool s8 ) { 55fn (q ,64 ,threads ,src ,out ); 56double best = 1e30 ; 57for (int k = 0 ;k < 3 ;++ k )best = std::min (best ,fn (q ,reps ,threads ,src ,out )); 58const double ops = 2.0 * 8 * 16 * (s8 ?32 :16 )* (double )mt * nt * reps * threads ; 59 std::printf ("%-22s %.1f T%s/s (%.3f s)\n" ,nm ,ops /best /1e12 ,s8 ?"OPS" :"FLOPS" ,best ); 60 }; 61rep ("fp16 4x2 grf256" ,run < false,4 ,2 ,256 > ,4 ,2 , false); 62rep ("fp16 4x2 grf128" ,run < false,4 ,2 ,128 > ,4 ,2 , false); 63rep ("fp16 2x2 grf256" ,run < false,2 ,2 ,256 > ,2 ,2 , false); 64rep ("s8 4x2 grf256" ,run < true,4 ,2 ,256 > ,4 ,2 , true); 65rep ("s8 4x2 grf128" ,run < true,4 ,2 ,128 > ,4 ,2 , true); 66rep ("s8 2x2 grf256" ,run < true,2 ,2 ,256 > ,2 ,2 , true); 67return 0 ; 68}