Skip to content

Commit

Permalink
gpu: jit: skip binary check for zebin
Browse files Browse the repository at this point in the history
  • Loading branch information
petercad authored and vpirogov committed Dec 13, 2023
1 parent 8892e7e commit 7dfcd11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/gpu/jit/binary_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,40 +144,45 @@ class binary_format_kernel_t : public jit_generator<hw> {
threadend(SWSB(sb2, 1), r127);
}

static compute::kernel_t make_kernel(compute::compute_engine_t *engine) {
static compute::kernel_t make_kernel(
compute::compute_engine_t *engine, bool *skip_check) {
compute::kernel_t kernel;

*skip_check = false;

if (hw != HW::Unknown) {
binary_format_kernel_t<hw> binary_format_kernel;

auto status
= engine->create_kernel(&kernel, &binary_format_kernel, {});

if (status != status::success) return nullptr;
*skip_check = binary_format_kernel.binaryIsZebin();
} else {
switch (engine->device_info()->gpu_arch()) {
case compute::gpu_arch_t::gen9:
kernel = binary_format_kernel_t<HW::Gen9>::make_kernel(
engine);
engine, skip_check);
break;
case compute::gpu_arch_t::gen11:
kernel = binary_format_kernel_t<HW::Gen11>::make_kernel(
engine);
engine, skip_check);
break;
case compute::gpu_arch_t::xe_lp:
kernel = binary_format_kernel_t<HW::XeLP>::make_kernel(
engine);
engine, skip_check);
break;
case compute::gpu_arch_t::xe_hp:
kernel = binary_format_kernel_t<HW::XeHP>::make_kernel(
engine);
engine, skip_check);
break;
case compute::gpu_arch_t::xe_hpg:
kernel = binary_format_kernel_t<HW::XeHPG>::make_kernel(
engine);
engine, skip_check);
break;
case compute::gpu_arch_t::xe_hpc:
kernel = binary_format_kernel_t<HW::XeHPC>::make_kernel(
engine);
engine, skip_check);
break;
case compute::gpu_arch_t::unknown: kernel = nullptr; break;
}
Expand All @@ -199,9 +204,16 @@ status_t gpu_supports_binary_format(bool *ok, engine_t *engine) {
auto stream = utils::downcast<compute::compute_stream_t *>(stream_generic);
if (!stream) return status::invalid_arguments;

auto kernel = binary_format_kernel_t<HW::Unknown>::make_kernel(gpu_engine);
bool skip_check = false;
auto kernel = binary_format_kernel_t<HW::Unknown>::make_kernel(
gpu_engine, &skip_check);
if (!kernel) return status::success;

if (skip_check) {
*ok = true;
return status::success;
}

// Binary kernel check.
uint32_t magic0 = MAGIC0;
uint64_t magic1 = MAGIC1;
Expand Down
4 changes: 4 additions & 0 deletions src/gpu/jit/ngen/ngen_opencl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ class OpenCLCodeGenerator : public ELFCodeGenerator<hw>

inline std::vector<uint8_t> getBinary(cl_context context, cl_device_id device, const std::string &options = "-cl-std=CL2.0");
inline cl_kernel getKernel(cl_context context, cl_device_id device, const std::string &options = "-cl-std=CL2.0");
bool binaryIsZebin() { return isZebin; }

static inline HW detectHW(cl_context context, cl_device_id device);
static inline void detectHWInfo(cl_context context, cl_device_id device, HW &outHW, Product &outProduct);

/* Deprecated. Use the Product-based API instead. */
static inline void detectHWInfo(cl_context context, cl_device_id device, HW &outHW, int &outStepping);

private:
bool isZebin = false;
inline std::vector<uint8_t> getPatchTokenBinary(cl_context context, cl_device_id device, const std::vector<uint8_t> *code = nullptr, const std::string &options = "-cl-std=CL2.0");
};

Expand Down Expand Up @@ -162,6 +165,7 @@ std::vector<uint8_t> OpenCLCodeGenerator<hw>::getBinary(cl_context context, cl_d

for (bool defaultFormat : {true, false}) {
bool legacy = defaultFormat ^ zebinFirst;
isZebin = !legacy;

if (legacy) {
try {
Expand Down

0 comments on commit 7dfcd11

Please sign in to comment.