oneMKL GPU dgemm and strided dgemm_batch return wrong results when lda exceeds 2^21 (16 MiB stride) on Intel Data Center GPU Max 1550
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 39/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- cpp
- Ambito
- backend, performance
Direzione di ricerca
Start by building the provided standalone reproducers with the listed icpx commands and confirm the failure at lda = 2097153 on the specified GPU. The payload points to oneMKL’s GPU GEMM implementation under oneMath, but does not identify source files or tests to inspect. Done means both gemm and strided gemm_batch match the host reference above the reported threshold.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
On Intel Data Center GPU Max 1550 (PVC), double-precision gemm and strided gemm_batch (column-major, USM) return wrong results as soon as the leading dimension exceeds 2097152 elements, a stride of 16777216 bytes (2^24). At lda = 2097152 the results are correct to rounding (relative error ~1e-15); at lda = 2097153 every member, or every entry, is wrong (relative error ~2). JIT and AOT builds behave identically. The same strided gemm_batch case is wrong through oneMath v0.9 (mklgpu backend), and plain oneMKL gemm fails as well, so the defect is probably in the oneMKL GPU library under oneMath.
Version
oneMath v0.9 (latest release tag), mklgpu backend. Not a known regression: no earlier version was tested. The develop branch (c430a941a at the time of testing) was not built.
Environment
- HW: Intel Data Center GPU Max 1550, one stack (
ZE_AFFINITY_MASK=0) - Backend library: oneMKL from oneAPI 2026.1.0
- OS: SUSE Linux Enterprise Server 15 SP7 (SLES 15.7), kernel 6.4.0-150700.53.78-default (Aurora, ALCF)
- Compiler: icpx 2026.1.0.20260617
- Level Zero GPU driver 1.6.33578+77 (intel-level-zero-gpu-1.6.33578.77-1146), loader 1.24.0
- CMake output log: not applicable, the reproducers are built with
icpxdirectly (commands below)
Steps to reproduce
Two standalone programs, below. Each runs the failing shape at lda = 2097152 (correct) and lda = 2097153 (wrong) and compares against a host reference.
icpx -fsycl -qmkl minimal_repro.cc -o minimal_repro_jit
icpx -fsycl -qmkl -fsycl-targets=spir64_gen -Xsycl-target-backend "-device pvc" minimal_repro.cc -o minimal_repro_aot
icpx -fsycl -qmkl minimal_repro_gemm.cc -o minimal_repro_gemm
ZE_AFFINITY_MASK=0 ./minimal_repro_jit
ZE_AFFINITY_MASK=0 ./minimal_repro_aot
ZE_AFFINITY_MASK=0 ./minimal_repro_gemm
# through oneMath: icpx -fsycl -DUSE_ONEMATH -I<onemath>/include minimal_repro_gemm.cc -L<onemath>/lib -lonemath
gemm_batch case: double, column-major, op(A) = A^T, op(B) = B, m = 4, n = 8, k = 8192, batch = 256, lda = ldb = ld, strideA = strideB = 8192, ldc = 4, strideC = 32, alpha = 1, beta = 0. The member address ranges interleave, but each member reads disjoint elements; the result is also wrong with fully disjoint A / B members (strideA = ldam, strideB = ldbn, batch 128).
gemm case: double, column-major, m = M, n = k = 4, lda = ldc = M, ldb = 4.
minimal_repro.cc (strided gemm_batch):
// Minimal reproducer: oneMKL column-major strided gemm_batch returns wrong results on Intel Data Center GPU Max
// (PVC) when the leading dimension of A (or B) exceeds 2^24 bytes, for a window of shapes/batch counts.
// Case: double, op(A) = A^T, op(B) = B, m = 4, n = 8, k = 8192, batch = 256,
// lda = ldb = LD, strideA = strideB = 8192 (members are consecutive row-chunks of two tall matrices),
// ldc = 4, strideC = 32 (C members disjoint).
// LD = 2097152 (2^24 B) is correct; LD = 2097153 is wrong in every member. Reference: host long-double dot products.
// Build: icpx -fsycl -qmkl minimal_repro.cc -o minimal_repro (AOT optional: -fsycl-targets=spir64_gen -Xsycl-target-backend "-device pvc")
#include <sycl/sycl.hpp>
#include <oneapi/mkl.hpp>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <vector>
static int
run(sycl::queue &q, std::int64_t ld)
{
const std::int64_t m = 4, n = 8, k = 8192, batch = 256, s = 8192, ldc = 4, sc = m * n;
const std::int64_t lenA = (batch - 1) * s + ld * m, lenB = (batch - 1) * s + ld * n;
std::vector<double> hA(lenA), hB(lenB), hC(batch * sc);
for (std::int64_t i = 0; i < lenA; ++i) hA[i] = std::sin(0.001 * (double)i);
for (std::int64_t i = 0; i < lenB; ++i) hB[i] = std::cos(0.0007 * (double)i);
double *A = sycl::malloc_device<double>(lenA, q), *B = sycl::malloc_device<double>(lenB, q),
*C = sycl::malloc_device<double>(batch * sc, q);
q.memcpy(A, hA.data(), lenA * 8);
q.memcpy(B, hB.data(), lenB * 8);
q.fill(C, 0.0, batch * sc).wait();
oneapi::mkl::blas::column_major::gemm_batch(q, oneapi::mkl::transpose::trans, oneapi::mkl::transpose::nontrans, m, n,
k, 1.0, A, ld, s, B, ld, s, 0.0, C, ldc, sc, batch)
.wait_and_throw();
q.memcpy(hC.data(), C, batch * sc * 8).wait();
int bad = 0;
double worst = 0;
for (std::int64_t b = 0; b < batch; ++b)
{
double err = 0, ref = 1e-300;
for (std::int64_t j = 0; j < n; ++j)
for (std::int64_t i = 0; i < m; ++i)
{
long double r = 0; // C_b(i,j) = sum_t A[b*s + t + i*ld] * B[b*s + t + j*ld]
for (std::int64_t t = 0; t < k; ++t) r += (long double)hA[b * s + t + i * ld] * hB[b * s + t + j * ld];
err = std::fmax(err, std::fabs(hC[b * sc + i + j * ldc] - (double)r));
ref = std::fmax(ref, std::fabs((double)r));
}
worst = std::fmax(worst, err / ref);
bad += err / ref > 1e-10;
}
std::printf("lda = ldb = %lld (%lld bytes): max rel error %.3e, wrong members %d / %lld %s\n", (long long)ld,
(long long)(ld * 8), worst, bad, (long long)batch, bad ? "WRONG" : "ok");
sycl::free(A, q); sycl::free(B, q); sycl::free(C, q);
return bad != 0;
}
int
main()
{
sycl::queue q{sycl::gpu_selector_v, sycl::property::queue::in_order{}};
std::printf("device: %s, driver %s\n", q.get_device().get_info<sycl::info::device::name>().c_str(),
q.get_device().get_info<sycl::info::device::driver_version>().c_str());
const int r0 = run(q, 2097152); // 2^21 doubles = 2^24 bytes: correct
const int r1 = run(q, 2097153); // one element more: wrong
return r0 + r1;
}
minimal_repro_gemm.cc (non-batched gemm, builds against oneMKL or oneMath):
// Minimal reproducer (item 2): oneMKL column-major NON-batched gemm returns wrong results on Intel Data Center GPU Max
// (PVC) for a tall-skinny product with a 4 x 4 right factor once the row count / leading dimension exceeds 2^24 bytes.
// Case: double, op(A) = A, op(B) = B, m = M, n = 4, k = 4, lda = ldc = M, ldb = 4, alpha = 1, beta = 0.
// M = 2097152 (2^24 B) is correct; M = 2097153 is wrong. Reference: host dot products.
// Build: icpx -fsycl -qmkl minimal_repro_gemm.cc -o minimal_repro_gemm (AOT optional: -fsycl-targets=spir64_gen -Xsycl-target-backend "-device pvc")
// oneMath: -DUSE_ONEMATH -I<onemath>/include -L<onemath>/lib -lonemath
#include <sycl/sycl.hpp>
#if defined(USE_ONEMATH)
# include <oneapi/math.hpp>
namespace blas = oneapi::math::blas::column_major;
using oneapi::math::transpose;
#else
# include <oneapi/mkl.hpp>
namespace blas = oneapi::mkl::blas::column_major;
using oneapi::mkl::transpose;
#endif
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <vector>
static int
run(sycl::queue &q, std::int64_t M)
{
const std::int64_t n = 4, k = 4;
std::vector<double> hA(M * k), hB(k * n), hC(M * n);
for (std::int64_t i = 0; i < M * k; ++i) hA[i] = std::sin(0.001 * (double)i);
for (std::int64_t i = 0; i < k * n; ++i) hB[i] = std::cos(0.7 * (double)i);
double *A = sycl::malloc_device<double>(M * k, q), *B = sycl::malloc_device<double>(k * n, q),
*C = sycl::malloc_device<double>(M * n, q);
q.memcpy(A, hA.data(), M * k * 8);
q.memcpy(B, hB.data(), k * n * 8);
q.fill(C, 0.0, M * n).wait();
blas::gemm(q, transpose::nontrans, transpose::nontrans, M, n, k, 1.0, A, M, B, k, 0.0, C, M).wait_and_throw();
q.memcpy(hC.data(), C, M * n * 8).wait();
double err = 0, ref = 1e-300;
std::int64_t bad = 0;
for (std::int64_t j = 0; j < n; ++j)
for (std::int64_t t = 0; t < M; ++t)
{
double r = 0; // C(t,j) = sum_i A(t,i) B(i,j)
for (std::int64_t i = 0; i < k; ++i) r += hA[t + i * M] * hB[i + j * k];
const double e = std::fabs(hC[t + j * M] - r);
err = std::fmax(err, e);
ref = std::fmax(ref, std::fabs(r));
bad += e > 1e-12 * (1.0 + std::fabs(r));
}
std::printf("m = lda = ldc = %lld (%lld bytes), n = k = 4: max rel error %.3e, wrong entries %lld / %lld %s\n",
(long long)M, (long long)(M * 8), err / ref, (long long)bad, (long long)(M * n), bad ? "WRONG" : "ok");
sycl::free(A, q); sycl::free(B, q); sycl::free(C, q);
return bad != 0;
}
int
main()
{
sycl::queue q{sycl::gpu_selector_v, sycl::property::queue::in_order{}};
std::printf("device: %s, driver %s\n", q.get_device().get_info<sycl::info::device::name>().c_str(),
q.get_device().get_info<sycl::info::device::driver_version>().c_str());
const int r0 = run(q, 2097152); // 2^21 doubles = 2^24 bytes: correct
const int r1 = run(q, 2097153); // one row more: wrong
return r0 + r1;
}
Observed behavior
(max relative error against a host reference; expected ~1e-15 everywhere)
| call | shape | lda (elements) | stride (bytes) | max rel. error | wrong |
|---|---|---|---|---|---|
| gemm_batch, strided, batch 256 | m = 4, n = 8, k = 8192 | 2097152 | 16777216 | 8.75e-15 | 0 / 256 members |
| gemm_batch, strided, batch 256 | same | 2097153 | 16777224 | 2.0 | 256 / 256 members |
| gemm, n = k = 4 | m = lda = ldc = 2097152 | 2097152 | 16777216 | 2.6e-16 | 0 entries |
| gemm, n = k = 4 | m = lda = ldc = 2097153 | 2097153 | 16777224 | 1.99 | 8388612 / 8388612 entries |
Threshold sweep:
| call | precision | correct at lda | wrong at lda |
|---|---|---|---|
| gemm_batch (T,N), batch 256-329 | double | 2097151, 2097152 | every lda tried from 2097153 to 5000000 (all members) |
| gemm_batch (T,N) | single | 2097153, 2340619, 3000000, 4194303, 4194304 | every lda tried from 4194305 to 6000000 |
| gemm (n = k = 4) | double | 1000000, 2097152 | 2097153, 2340619, 3000000, 4194305, 8000000 |
At lda = 3000000 the double gemm_batch result also depends on the batch size: wrong at batch 256,
329 and 330, correct at 340, 341 and 384 (the same window as at lda = 2097153).
The boundary at a 2^24-byte stride suggests an offset computation limited to 24 bits somewhere
in the GPU kernel or its dispatch (our inference). Keeping the leading-dimension stride at or below
16 MiB avoids the wrong results. In our application we replaced the batched split-K call with a
single non-batched GEMM ('T','N') over the full length, where the long dimension is k; we have not
found a general workaround for the other shapes (the plain-gemm case above still fails).
Through oneMath v0.9 (mklgpu), the strided gemm_batch case above gives max relative error 2.64 with 256 / 256 members wrong at lda = 2097153, and 9.92e-15 at lda = 2097152.
Expected behavior
Relative error ~1e-15 for every lda, as at lda <= 2097152.
- Lingua principale
- C++
- Stelle
- 777
- Fork
- 183
- Merge medio
- 2g 16h
- PR unite (30g)
- 6
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di uxlfoundation/oneMath
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 8/100
uxlfoundation/oneMath#789 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 8/100
uxlfoundation/oneMath#786 ·
I maintainer di solito rispondono entro 1 giorno
-
[DFT][rocFFT] Add regression tests for stride validation and rank handlingForse già presa @zjin-lcf l’ha presa 55 giorni fa. Aperta
Difficoltà 4/5 1-2 giorni Idoneità per principianti 35/100
uxlfoundation/oneMath#771 ·
I maintainer di solito rispondono entro 1 giorno
-
Example code for SYCL generic BLAS and portFFT backendsForse già presa @zjin-lcf l’ha presa 106 giorni fa. Aperta
Difficoltà 3/5 Mezza giornata Idoneità per principianti 22/100
uxlfoundation/oneMath#714 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
uxlfoundation/oneMath#711 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di uxlfoundation/oneMath
Issue simili
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
patrick-hudson/put.gd-desktop#2044 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
uxlfoundation/oneDNN#6604 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
[Bug]: RoundToNearest truncates in plugins compiled with spcomp 1.13Forse già presa @fmu1337 l’ha presa oggi. ApertaBug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
alliedmodders/sourcemod#2627 ·
I maintainer di solito rispondono entro 1 giorno