// Phase 0 device probe: limits, aspects, sub-groups, joint_matrix combinations, and a // numerical check of which XMX element types actually execute on the device. #include #include #include #include namespace syclex = sycl::ext::oneapi::experimental; namespace jm = sycl::ext::oneapi::experimental::matrix; static const char *mt(jm::matrix_type t) { switch (t) { case jm::matrix_type::bf16: return "bf16"; case jm::matrix_type::fp16: return "fp16"; case jm::matrix_type::tf32: return "tf32"; case jm::matrix_type::fp32: return "fp32"; case jm::matrix_type::fp64: return "fp64"; case jm::matrix_type::sint8: return "s8"; case jm::matrix_type::uint8: return "u8"; case jm::matrix_type::sint32: return "s32"; case jm::matrix_type::uint32: return "u32"; default: return "other"; } } // One sub-group computes C[M x N] = A[M x K] * B[K x N] with joint_matrix, compared with a host loop. template static double jm_test(sycl::queue &q, const char *name) { std::vector a(M * K), b(K * N); std::vector c(M * N, 0); std::vector ref(M * N, 0); for (size_t i = 0; i < M * K; i++) a[i] = Ta(float(int(i * 7 % 11) - 5) * 0.25f); for (size_t i = 0; i < K * N; i++) b[i] = Ta(float(int(i * 5 % 13) - 6) * 0.5f); for (size_t m = 0; m < M; m++) for (size_t n = 0; n < N; n++) for (size_t k = 0; k < K; k++) ref[m * N + n] += double(float(a[m * K + k])) * double(float(b[k * N + n])); Ta *da = sycl::malloc_device(M * K, q), *db = sycl::malloc_device(K * N, q); Tc *dc = sycl::malloc_device(M * N, q); q.memcpy(da, a.data(), sizeof(Ta) * M * K); q.memcpy(db, b.data(), sizeof(Ta) * K * N); q.memset(dc, 0, sizeof(Tc) * M * N).wait(); try { q.parallel_for(sycl::nd_range<1>{16, 16}, [=](sycl::nd_item<1> it) [[sycl::reqd_sub_group_size(16)]] { auto sg = it.get_sub_group(); jm::joint_matrix ma; jm::joint_matrix mb; jm::joint_matrix mc; jm::joint_matrix_fill(sg, mc, Tc(0)); auto pa = sycl::address_space_cast(da); auto pb = sycl::address_space_cast(db); auto pc = sycl::address_space_cast(dc); jm::joint_matrix_load(sg, ma, pa, K); jm::joint_matrix_load(sg, mb, pb, N); jm::joint_matrix_mad(sg, mc, ma, mb, mc); jm::joint_matrix_store(sg, mc, pc, N, jm::layout::row_major); }).wait_and_throw(); } catch (sycl::exception &e) { printf(" jm %-28s FAILED: %s\n", name, e.what()); return -1; } q.memcpy(c.data(), dc, sizeof(Tc) * M * N).wait(); double maxerr = 0; for (size_t i = 0; i < M * N; i++) maxerr = std::fmax(maxerr, std::fabs(double(c[i]) - ref[i])); printf(" jm %-28s M%zu N%zu K%zu max|err|=%g\n", name, M, N, K, maxerr); sycl::free(da, q); sycl::free(db, q); sycl::free(dc, q); return maxerr; } int main() { sycl::queue q{sycl::gpu_selector_v, sycl::property::queue::in_order{}}; auto d = q.get_device(); printf("device: %s\n", d.get_info().c_str()); printf("backend: %s driver: %s\n", d.get_backend() == sycl::backend::ext_oneapi_level_zero ? "level_zero" : "other", d.get_info().c_str()); printf("max_compute_units: %u\n", d.get_info()); printf("max_work_group_size: %zu\n", d.get_info()); printf("sub_group_sizes:"); for (auto s : d.get_info()) printf(" %zu", s); printf("\nlocal_mem_size: %llu\n", (unsigned long long)d.get_info()); printf("global_mem_size: %llu (%.2f GiB)\n", (unsigned long long)d.get_info(), d.get_info() / 1073741824.0); printf("max_mem_alloc_size: %llu (%.2f GiB)\n", (unsigned long long)d.get_info(), d.get_info() / 1073741824.0); printf("max_clock_frequency: %u MHz\n", d.get_info()); printf("global_mem_cache_size: %llu\n", (unsigned long long)d.get_info()); printf("aspects: fp16=%d fp64=%d usm_device=%d usm_host=%d usm_shared=%d usm_system=%d atomic64=%d intel_matrix=%d\n", d.has(sycl::aspect::fp16), d.has(sycl::aspect::fp64), d.has(sycl::aspect::usm_device_allocations), d.has(sycl::aspect::usm_host_allocations), d.has(sycl::aspect::usm_shared_allocations), d.has(sycl::aspect::usm_system_allocations), d.has(sycl::aspect::atomic64), d.has(sycl::aspect::ext_intel_matrix)); try { auto arch = d.get_info(); printf("architecture enum: %d (bmg_g31=%d)\n", int(arch), int(syclex::architecture::intel_gpu_bmg_g31)); } catch (...) { printf("architecture: query failed\n"); } printf("matrix_combinations:\n"); try { auto combos = d.get_info(); for (auto &c : combos) printf(" A=%s B=%s C=%s D=%s M=%zu N=%zu K=%zu (max M %zu N %zu K %zu)\n", mt(c.atype), mt(c.btype), mt(c.ctype), mt(c.dtype), c.msize, c.nsize, c.ksize, c.max_msize, c.max_nsize, c.max_ksize); if (combos.empty()) printf(" (none)\n"); } catch (sycl::exception &e) { printf(" query failed: %s\n", e.what()); } printf("joint_matrix execution checks:\n"); jm_test(q, "bf16 x bf16 -> f32"); jm_test(q, "fp16 x fp16 -> f32"); jm_test(q, "s8 x s8 -> s32"); return 0; }