Archived
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
68 lines
2.4 KiB
C++
68 lines
2.4 KiB
C++
/* xe2_common.h -- what every libxe2 kernel shares: the queue a launch submits to, row geometry,
|
|
* and the dtype conversions.
|
|
*
|
|
* Correctness first (docs/SYCL_PORTING.md §4.8): the conversions are rad_plugin.h's, the ones
|
|
* libref computes with, so a result rounds where the reference's does. Device code is compiled
|
|
* with -ffp-contract=off for the same reason (libxe2/CMakeLists.txt). A kernel that cannot serve
|
|
* the geometry it is handed returns RAD_E_UNSUPPORTED and names why through xe2_refuse; it never
|
|
* hands the work to the host.
|
|
*/
|
|
#pragma once
|
|
#include "rad_abi.h"
|
|
#include "rad_plugin.h"
|
|
#include "rad_sycl.h"
|
|
|
|
#include <sycl/sycl.hpp>
|
|
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
|
|
namespace xe2 {
|
|
|
|
namespace syclex = sycl::ext::oneapi::experimental;
|
|
|
|
/* The sub-group every libxe2 kernel is written for: Xe2's native SIMD16. */
|
|
constexpr int kSub = 16;
|
|
|
|
/* Why the last launch on this thread refused, for the engine's error report and the tests. */
|
|
const char* last_refusal();
|
|
int refuse(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
|
|
|
|
/* A row-major view of an operand read as rows of `n` elements: the base, and the element distance
|
|
* between consecutive rows. A tensor whose last axis is `n` may have padded rows, provided every
|
|
* leading axis collapses to one uniform pitch; anything else (`n` not the last extent) must be
|
|
* contiguous and is read as rows of `n`. The last axis must have stride 1. */
|
|
struct Rows {
|
|
char* base = nullptr;
|
|
int64_t pitch = 0; /* elements */
|
|
int64_t rows = 0;
|
|
uint32_t dtype = 0;
|
|
};
|
|
|
|
/* Fills `out` for `t` read as rows of `n`; RAD_E_UNSUPPORTED (with a reason) for a layout the
|
|
* kernels do not stride over. `rows` is numel / n, as libref counts them. */
|
|
int rows_view(const RadTensor* t, int64_t n, Rows* out, const char* what);
|
|
|
|
/* The queue behind a launch's stream, or null with a reason (not a SYCL stream). */
|
|
sycl::queue* queue_of(RadStream s);
|
|
|
|
/* Runs `submit`, turning a SYCL exception into RAD_E_DEVICE with its message. */
|
|
template <typename F>
|
|
int submit(F&& f) {
|
|
try {
|
|
f();
|
|
} catch (const sycl::exception& e) {
|
|
return refuse("SYCL: %s", e.what());
|
|
}
|
|
return RAD_OK;
|
|
}
|
|
|
|
/* Rounds `v` through a store and load of `dt`, as libref's round_dt does. */
|
|
inline float round_dt(uint32_t dt, float v) {
|
|
uint64_t buf = 0;
|
|
rad_store_f32(&buf, dt, 0, v);
|
|
return rad_load_f32(&buf, dt, 0);
|
|
}
|
|
|
|
} // namespace xe2
|