Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/source/builder/writing-kernels.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,18 @@ The following sections enumerate all supported options for `build.toml`.
is provided for kernels that require functionality only provided by newer CUDA
toolkits.

### `general.xpu`

- `cri-grf-size` (optional): the number of GRF registers per thread (128, 256,
or 512) for the CRI (Xe3P) kernels that do not request a size with a kernel
property. This lets kernels use 512 GRF, which the `grf_size` kernel property
does not support. It is an option for the whole AOT image, so it also applies
to kernels that come from other `kernel.<name>` sections. Use `grf_size<256>`
on kernels that should not get the larger GRF. This option requires a kernel
that depends on `sycl_tla` and is built for CRI only (with
`-D__SYCL_TARGET_INTEL_GPU_CRI__=1` in its `sycl-flags`), because the option
is not supported for other GPUs.

### Framework sections

The framework section specifies framework-specific settings. The name of the
Expand Down
114 changes: 111 additions & 3 deletions kernel-builder/src/pyproject/deps.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashSet;
use std::io::Write;

use eyre::{Context, Result};
use eyre::{bail, Context, Result};
use minijinja::{context, Environment};

use kernels_common::config::{Build, Dependency};
Expand All @@ -13,6 +13,13 @@ pub fn render_deps(env: &Environment, build: &Build, write: &mut impl Write) ->
deps.extend(kernel.depends())
}

// Only the sycl-tla setup composes the AOT options, do not drop the
// GRF size silently.
let cri_grf_size = build.general.xpu.as_ref().and_then(|xpu| xpu.cri_grf_size);
if cri_grf_size.is_some() && !deps.contains(&Dependency::SyclTla) {
bail!("`general.xpu.cri-grf-size` needs a kernel that depends on `sycl-tla`");
}

for dep in deps {
match dep {
Dependency::Cutlass2_10 => {
Expand Down Expand Up @@ -97,6 +104,11 @@ pub fn render_deps(env: &Environment, build: &Build, write: &mut impl Write) ->
// generic image, so that image can only lower to cri and pvc/bmg need
// alias targets. Otherwise one image serves all three, halving the
// device compilations per TU.
//
// The SYCL runtime takes the last AOT image that matches a
// device, and a spir64_gen image matches every Intel GPU, so
// spir64_gen must come before the aliases. spir64 is the JIT
// image for other GPUs.
let cri_isolated_image = build.kernels.values().any(|kernel| {
kernel.sycl_flags().is_some_and(|flags| {
flags
Expand All @@ -105,14 +117,32 @@ pub fn render_deps(env: &Environment, build: &Build, write: &mut impl Write) ->
})
});
let (sycl_aot_devices, sycl_offload_targets) = if cri_isolated_image {
("cri", "intel_gpu_pvc,intel_gpu_bmg_g21,spir64_gen,spir64")
("cri", "spir64_gen,intel_gpu_pvc,intel_gpu_bmg_g21,spir64")
} else {
("pvc,bmg-g21,cri", "spir64_gen,spir64")
};
// The GRF size is an ocloc option for the whole image, which
// crashes ocloc for pvc and bmg-g21, so it needs the cri-only
// image.
let sycl_aot_internal_options = match cri_grf_size {
None => None,
Some(size) if !matches!(size, 128 | 256 | 512) => {
bail!("`general.xpu.cri-grf-size` must be 128, 256, or 512, got {size}")
}
Some(_) if !cri_isolated_image => bail!(
"`general.xpu.cri-grf-size` needs a kernel built for CRI only \
(`-D__SYCL_TARGET_INTEL_GPU_CRI__=1` in its `sycl-flags`)"
),
Some(size) => Some(format!("-cl-intel-{size}-GRF-per-thread")),
};
env.get_template("xpu/dep-sycl-tla.cmake")
.wrap_err("Cannot get SYCL TLA dependency template")?
.render_captured_to(
context! { sycl_aot_devices, sycl_offload_targets },
context! {
sycl_aot_devices,
sycl_offload_targets,
sycl_aot_internal_options,
},
&mut *write,
)
.wrap_err("Cannot render SYCL TLA dependency template")?;
Expand All @@ -128,3 +158,81 @@ pub fn render_deps(env: &Environment, build: &Build, write: &mut impl Write) ->

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

fn render(general_xpu: &str, cri_kernel: bool) -> Result<String> {
let cri_flags = if cri_kernel {
r#"sycl-flags = ["-fsycl-targets=spir64_gen", "-D__SYCL_TARGET_INTEL_GPU_CRI__=1"]"#
} else {
""
};
let tmp = tempfile::tempdir().unwrap();
std::fs::write(
tmp.path().join("build.toml"),
format!(
r#"
[general]
name = "xpu-demo"
version = 1
edition = 6
license = "Apache-2.0"
backends = ["xpu"]

{general_xpu}

[torch]
src = ["torch-ext/torch_binding.cpp"]

[kernel.demo_xpu]
language = "cpp-xpu"
depends = ["torch", "sycl_tla"]
src = ["demo/demo.cpp"]
{cri_flags}
"#
),
)
.unwrap();
let build = Build::open(tmp.path()).unwrap();

let mut env = Environment::new();
minijinja_embed::load_templates!(&mut env);
let mut rendered = vec![];
render_deps(&env, &build, &mut rendered)?;
Ok(String::from_utf8(rendered).unwrap())
}

#[test]
fn cri_grf_size_sets_ocloc_internal_options() {
let rendered = render("[general.xpu]\ncri-grf-size = 512", true).unwrap();
assert!(rendered.contains(r#"set(SYCL_AOT_DEVICES "cri")"#));
assert!(rendered.contains(
r#"set(SYCL_OFFLOAD_TARGETS "spir64_gen,intel_gpu_pvc,intel_gpu_bmg_g21,spir64")"#
));
assert!(
rendered.contains(r#"set(SYCL_AOT_INTERNAL_OPTIONS "-cl-intel-512-GRF-per-thread")"#)
);
}

#[test]
fn no_cri_grf_size_keeps_ocloc_defaults() {
let rendered = render("", true).unwrap();
assert!(!rendered.contains("SYCL_AOT_INTERNAL_OPTIONS"));
}

#[test]
fn cri_grf_size_needs_cri_only_image() {
let err = render("[general.xpu]\ncri-grf-size = 512", false).unwrap_err();
assert!(err
.to_string()
.contains("needs a kernel built for CRI only"));
}

#[test]
fn cri_grf_size_rejects_unknown_size() {
let err = render("[general.xpu]\ncri-grf-size = 384", true).unwrap_err();
assert!(err.to_string().contains("must be 128, 256, or 512"));
}
}
12 changes: 10 additions & 2 deletions kernel-builder/src/pyproject/templates/torch/preamble.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ elseif(GPU_LANG STREQUAL "SYCL")
set(SYCL_OFFLOAD_TARGETS "spir64_gen,spir64")
set(SYCL_AOT_DEVICES "pvc,xe-lpg,ats-m150")
set(SYCL_AOT_BACKEND_OPTIONS " -cl-intel-enable-auto-large-GRF-mode -cl-poison-unsupported-fp64-kernels -cl-intel-greater-than-4GB-buffer-required")
# ocloc -internal_options, spir64_gen only (e.g. a GRF size for one device).
set(SYCL_AOT_INTERNAL_OPTIONS "")
set(SYCL_SPIRV_EXT "")

# Rebuild sycl_flags (compile) and sycl_link_flags (link) from the variables
Expand All @@ -231,14 +233,20 @@ elseif(GPU_LANG STREQUAL "SYCL")
# Backend options reach one target each: spir64_gen takes -device, the
# intel_gpu_* aliases imply theirs. SHELL: stops CMake from deduplicating
# the identical -options and silently dropping all but the first target.
# -exclude_ir: AOT images do not carry a SPIR-V copy (spir64 is the JIT
# image when there is one).
string(REPLACE "," ";" _sycl_aot_targets "${SYCL_OFFLOAD_TARGETS}")
set(_sycl_aot_internal_options "")
if(SYCL_AOT_INTERNAL_OPTIONS)
set(_sycl_aot_internal_options " -internal_options ${SYCL_AOT_INTERNAL_OPTIONS}")
endif()
foreach(_tgt IN LISTS _sycl_aot_targets)
if(_tgt STREQUAL "spir64_gen")
string(APPEND sycl_link_flags
";SHELL:-Xsycl-target-backend=spir64_gen \"-device ${SYCL_AOT_DEVICES} -options '${SYCL_AOT_BACKEND_OPTIONS}'\"")
";SHELL:-Xsycl-target-backend=spir64_gen \"-device ${SYCL_AOT_DEVICES} -exclude_ir${_sycl_aot_internal_options} -options '${SYCL_AOT_BACKEND_OPTIONS}'\"")
elseif(_tgt MATCHES "^intel_gpu_")
string(APPEND sycl_link_flags
";SHELL:-Xsycl-target-backend=${_tgt} \"-options '${SYCL_AOT_BACKEND_OPTIONS}'\"")
";SHELL:-Xsycl-target-backend=${_tgt} \"-exclude_ir -options '${SYCL_AOT_BACKEND_OPTIONS}'\"")
endif()
endforeach()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ endif()
if(GPU_LANG STREQUAL "SYCL")
target_link_options(${OPS_NAME} PRIVATE ${sycl_link_flags})
target_link_libraries(${OPS_NAME} PRIVATE dnnl)
# The static symbol table and the device symbol table (.tgtsym) that
# the offload bundler adds are not loaded at runtime, but take tens of
# MB in large kernels.
add_custom_command(TARGET ${OPS_NAME} POST_BUILD
COMMAND ${CMAKE_STRIP} --strip-all --remove-section=.tgtsym $<TARGET_FILE:${OPS_NAME}>
VERBATIM)
endif()

# Compile Metal shaders if any were found
Expand Down
12 changes: 10 additions & 2 deletions kernel-builder/src/pyproject/templates/tvm_ffi/preamble.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ elseif(GPU_LANG STREQUAL "SYCL")
set(SYCL_OFFLOAD_TARGETS "spir64_gen,spir64")
set(SYCL_AOT_DEVICES "pvc,xe-lpg,ats-m150")
set(SYCL_AOT_BACKEND_OPTIONS " -cl-intel-enable-auto-large-GRF-mode -cl-poison-unsupported-fp64-kernels -cl-intel-greater-than-4GB-buffer-required")
# ocloc -internal_options, spir64_gen only (e.g. a GRF size for one device).
set(SYCL_AOT_INTERNAL_OPTIONS "")
set(SYCL_SPIRV_EXT "")

# Rebuild sycl_flags (compile) and sycl_link_flags (link) from the variables
Expand All @@ -192,14 +194,20 @@ elseif(GPU_LANG STREQUAL "SYCL")
# Backend options reach one target each: spir64_gen takes -device, the
# intel_gpu_* aliases imply theirs. SHELL: stops CMake from deduplicating
# the identical -options and silently dropping all but the first target.
# -exclude_ir: AOT images do not carry a SPIR-V copy (spir64 is the JIT
# image when there is one).
string(REPLACE "," ";" _sycl_aot_targets "${SYCL_OFFLOAD_TARGETS}")
set(_sycl_aot_internal_options "")
if(SYCL_AOT_INTERNAL_OPTIONS)
set(_sycl_aot_internal_options " -internal_options ${SYCL_AOT_INTERNAL_OPTIONS}")
endif()
foreach(_tgt IN LISTS _sycl_aot_targets)
if(_tgt STREQUAL "spir64_gen")
string(APPEND sycl_link_flags
";SHELL:-Xsycl-target-backend=spir64_gen \"-device ${SYCL_AOT_DEVICES} -options '${SYCL_AOT_BACKEND_OPTIONS}'\"")
";SHELL:-Xsycl-target-backend=spir64_gen \"-device ${SYCL_AOT_DEVICES} -exclude_ir${_sycl_aot_internal_options} -options '${SYCL_AOT_BACKEND_OPTIONS}'\"")
elseif(_tgt MATCHES "^intel_gpu_")
string(APPEND sycl_link_flags
";SHELL:-Xsycl-target-backend=${_tgt} \"-options '${SYCL_AOT_BACKEND_OPTIONS}'\"")
";SHELL:-Xsycl-target-backend=${_tgt} \"-exclude_ir -options '${SYCL_AOT_BACKEND_OPTIONS}'\"")
endif()
endforeach()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ target_link_rust_kernels(${OPS_NAME})
if(GPU_LANG STREQUAL "SYCL")
target_link_options(${OPS_NAME} PRIVATE ${sycl_link_flags})
target_link_libraries(${OPS_NAME} PRIVATE dnnl)
# The static symbol table and the device symbol table (.tgtsym) that
# the offload bundler adds are not loaded at runtime, but take tens of
# MB in large kernels.
add_custom_command(TARGET ${OPS_NAME} POST_BUILD
COMMAND ${CMAKE_STRIP} --strip-all --remove-section=.tgtsym $<TARGET_FILE:${OPS_NAME}>
VERBATIM)
endif()

# Compile Metal shaders if any were found
Expand Down
4 changes: 4 additions & 0 deletions kernel-builder/src/pyproject/templates/xpu/dep-sycl-tla.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ set(DPCPP_AOT_MIN_VERSION "2026.0")
if(DPCPP_VERSION VERSION_GREATER_EQUAL DPCPP_AOT_MIN_VERSION)
set(SYCL_AOT_DEVICES "{{ sycl_aot_devices }}")
set(SYCL_OFFLOAD_TARGETS "{{ sycl_offload_targets }}")
{% if sycl_aot_internal_options %}
# general.xpu.cri-grf-size: GRF size of the cri kernels that do not set one.
set(SYCL_AOT_INTERNAL_OPTIONS "{{ sycl_aot_internal_options }}")
{% endif %}
else()
set(SYCL_OFFLOAD_TARGETS "spir64")
endif()
Expand Down
1 change: 1 addition & 0 deletions kernels-common/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ pub struct CudaGeneral {
}

pub struct XpuGeneral {
pub cri_grf_size: Option<u32>,
pub kernel_depends: Option<Vec<KernelDependency>>,
pub python_depends: Option<Vec<String>>,
}
Expand Down
1 change: 1 addition & 0 deletions kernels-common/src/config/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ impl From<NeuronGeneral> for super::NeuronGeneral {
impl From<XpuGeneral> for super::XpuGeneral {
fn from(xpu: XpuGeneral) -> Self {
Self {
cri_grf_size: None,
kernel_depends: None,
python_depends: xpu.python_depends,
}
Expand Down
1 change: 1 addition & 0 deletions kernels-common/src/config/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ impl From<NeuronGeneral> for super::NeuronGeneral {
impl From<XpuGeneral> for super::XpuGeneral {
fn from(xpu: XpuGeneral) -> Self {
Self {
cri_grf_size: None,
kernel_depends: None,
python_depends: xpu.python_depends,
}
Expand Down
1 change: 1 addition & 0 deletions kernels-common/src/config/v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ impl From<TpuGeneral> for super::TpuGeneral {
impl From<XpuGeneral> for super::XpuGeneral {
fn from(xpu: XpuGeneral) -> Self {
Self {
cri_grf_size: None,
kernel_depends: xpu.kernel_depends,
python_depends: xpu.python_depends,
}
Expand Down
3 changes: 3 additions & 0 deletions kernels-common/src/config/v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub struct TpuGeneral {
#[derive(Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
pub struct XpuGeneral {
pub cri_grf_size: Option<u32>,
pub kernel_depends: Option<Vec<KernelDependency>>,
pub python_depends: Option<Vec<String>>,
}
Expand Down Expand Up @@ -356,6 +357,7 @@ impl From<TpuGeneral> for super::TpuGeneral {
impl From<XpuGeneral> for super::XpuGeneral {
fn from(xpu: XpuGeneral) -> Self {
Self {
cri_grf_size: xpu.cri_grf_size,
kernel_depends: xpu.kernel_depends,
python_depends: xpu.python_depends,
}
Expand Down Expand Up @@ -608,6 +610,7 @@ impl From<super::TpuGeneral> for TpuGeneral {
impl From<super::XpuGeneral> for XpuGeneral {
fn from(xpu: super::XpuGeneral) -> Self {
Self {
cri_grf_size: xpu.cri_grf_size,
kernel_depends: xpu.kernel_depends,
python_depends: xpu.python_depends,
}
Expand Down
26 changes: 13 additions & 13 deletions nix-builder/pkgs/xpu-packages/ocloc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@

stdenv.mkDerivation (finalAttrs: {
pname = "ocloc";
version = "26.22";
version = "26.44";

srcs = [
(fetchurl {
url = "https://github.com/intel/compute-runtime/releases/download/26.22.38646.4/intel-ocloc_26.22.38646.4-0_amd64.deb";
hash = "sha256-JXRYQeZiecf/H/bC1NqeyRFoXBLhycVgnZnk1Uo2TcA=";
url = "https://github.com/intel/compute-runtime/releases/download/26.44.40734.8/intel-ocloc_26.44.40734.8-0_amd64.deb";
hash = "sha256-/HO2difIVoLC+cRyZvMP4gkigBpl5i+GOSOvB/1nYX4=";
})
(fetchurl {
url = "https://github.com/intel/intel-graphics-compiler/releases/download/v2.36.3/intel-igc-core-2_2.36.3+21719_amd64.deb";
hash = "sha256-ngl1rHUBW0Meuy2oGoArn9HiijwnAxOpdWnNHmpsYEg=";
url = "https://github.com/intel/intel-graphics-compiler/releases/download/v2.43.9/intel-igc-core-2_2.43.9+23453_amd64.deb";
hash = "sha256-VSkW93HY7GmgToj3xadg8pycsjAtv3IeveIUTq6UgX8=";
})
(fetchurl {
url = "https://github.com/intel/intel-graphics-compiler/releases/download/v2.36.3/intel-igc-opencl-2_2.36.3+21719_amd64.deb";
hash = "sha256-NQpSMx54S7f7ntQumTtcRLfmVi/HTSzzECsptqV2+oU=";
url = "https://github.com/intel/intel-graphics-compiler/releases/download/v2.43.9/intel-igc-opencl-2_2.43.9+23453_amd64.deb";
hash = "sha256-rsCb8uHzD2v7eVl6QrP32ZNcWDXFz7+GPyjO/0j8iNY=";
})
(fetchurl {
url = "https://github.com/intel/compute-runtime/releases/download/26.22.38646.4/intel-opencl-icd_26.22.38646.4-0_amd64.deb";
hash = "sha256-b9rC6KKqz4ROv9kFIb9xArPrtE9pwbztGpeFp86Wo8I=";
url = "https://github.com/intel/compute-runtime/releases/download/26.44.40734.8/intel-opencl-icd_26.44.40734.8-0_amd64.deb";
hash = "sha256-nVSiOVfLaVqWAtOJ5w0SSzc0MxpzLn4gB0u2iU4iHSI=";
})
(fetchurl {
url = "https://github.com/intel/compute-runtime/releases/download/26.22.38646.4/libigdgmm12_22.10.0_amd64.deb";
hash = "sha256-YDGmPW6KEs5hwU78FfLI5ycGEobjgguFlObQBhXgTVQ=";
url = "https://github.com/intel/compute-runtime/releases/download/26.44.40734.8/libigdgmm12_22.10.2_amd64.deb";
hash = "sha256-BT/OrbhKHS+aMKDRvJsWQks/GpDMSZAPzYCq3PJcik0=";
})
(fetchurl {
url = "https://github.com/intel/compute-runtime/releases/download/26.22.38646.4/libze-intel-gpu1_26.22.38646.4-0_amd64.deb";
hash = "sha256-i++fJOA/gm+TwHYIG9oTxqw6+9nkK5+48pj6tlIzDi8=";
url = "https://github.com/intel/compute-runtime/releases/download/26.44.40734.8/libze-intel-gpu1_26.44.40734.8-0_amd64.deb";
hash = "sha256-ngozX/7ubTiXSyddB07yqVxI3d29UHr4EEGIVyeOgUI=";
})
];
dontStrip = true;
Expand Down
Loading