This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/libxe2/xe2_common.cpp
T
pascallinxweilerandClaude Opus 5.5 41a3c32a65 libxe2: the Intel kernel library's skeleton, and its first op, add
libxe2 is a kernel plugin like any other, built by rad_add_plugin from the icpx sub-build into the
build tree's $RADIANCE_HOME. It declares no schemas (every op it serves is libref's vocabulary), only
device rows, written with designated initialisers. xe2_common.h holds what every kernel needs: the
launch's queue (rad_sycl.h), row views over padded operands, refusals that name the geometry, and
libref's own dtype conversions so results round where the reference's do.

add passes rad-kbench against libref at tolerance zero, on the recorded fixture (30 cases) and on
MiniCPM5-2B's container (20 cases), inside guarded allocations. In a SYCL build the kbench replays
run libxe2 on the card, so they are labelled sycl there, as they are gpu in a HIP build.

scripts/sycl/notify.sh posts to the Discord webhook when the port needs the user.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
2026-10-23 15:55:39 +02:00

58 lines
1.9 KiB
C++

/* xe2_common.cpp -- the shared helpers of xe2_common.h. */
#include "xe2_common.h"
#include <cstdarg>
namespace xe2 {
namespace {
thread_local char t_refusal[512] = "";
}
const char* last_refusal() { return t_refusal; }
int refuse(const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
std::vsnprintf(t_refusal, sizeof t_refusal, fmt, ap);
va_end(ap);
std::fprintf(stderr, "libxe2: %s\n", t_refusal);
return RAD_E_UNSUPPORTED;
}
sycl::queue* queue_of(RadStream s) {
sycl::queue* q = rad_sycl_queue(s);
if (!q) refuse("the stream is not a SYCL stream of version %u (another backend?)",
RAD_SYCL_STREAM_VERSION);
return q;
}
int rows_view(const RadTensor* t, int64_t n, Rows* out, const char* what) {
if (!t || !t->data || n <= 0) return refuse("%s: missing operand or n <= 0", what);
out->base = (char*)t->data;
out->dtype = t->dtype;
out->rows = rad_tensor_numel(t) / n;
if (t->rank >= 2 && t->shape[t->rank - 1] == n) {
if (t->stride[t->rank - 1] != 1) return refuse("%s: last-axis stride %lld, not 1", what,
(long long)t->stride[t->rank - 1]);
/* Every leading axis must step by the one below it times its extent, so a row index maps
* to one pitch (libref's rowoff walks them; here they must agree). */
const int64_t pitch = t->stride[t->rank - 2];
int64_t span = pitch;
for (int i = (int)t->rank - 3; i >= 0; --i) {
span *= t->shape[i + 1];
if (t->shape[i] != 1 && t->stride[i] != span)
return refuse("%s: leading axes do not collapse to one row pitch", what);
}
out->pitch = pitch;
return RAD_OK;
}
if (!rad_tensor_is_contiguous(t))
return refuse("%s: read as rows of %lld but neither its last extent nor contiguous", what,
(long long)n);
out->pitch = n;
return RAD_OK;
}
} // namespace xe2