diff --git a/platforms/oneapi/libzml_oneapi.BUILD.bazel b/platforms/oneapi/libzml_oneapi.BUILD.bazel index 1011e7b6..eb08e652 100644 --- a/platforms/oneapi/libzml_oneapi.BUILD.bazel +++ b/platforms/oneapi/libzml_oneapi.BUILD.bazel @@ -47,12 +47,6 @@ patchelf( soname = "libze_intel_gpu.so.1", ) -patchelf( - name = "libigdrcl_so", - src = "@intel-opencl-icd//:libigdrcl_so", - set_rpath = "$ORIGIN", -) - patchelf( name = "libigc_so_2", src = "@libigc2//:libigc_so_2", @@ -101,7 +95,6 @@ copy_to_directory( ":libiga64_so_2", ":libigc_so_2", ":libigdfcl_so_2", - ":libigdrcl_so", ":libsycl_so", ":libtbb_so_12", ":libze_intel_gpu_so", @@ -135,7 +128,6 @@ copy_to_directory( replace_prefixes = { "libiga64_so_2": "lib", "libigdfcl_so_2": "lib", - "libigdrcl_so": "lib", "libigc_so_2": "lib", "libdnnl_so_3": "lib", "libzml_oneapi_so": "lib", diff --git a/platforms/oneapi/oneapi.bzl b/platforms/oneapi/oneapi.bzl index 642793fb..a3c968d3 100644 --- a/platforms/oneapi/oneapi.bzl +++ b/platforms/oneapi/oneapi.bzl @@ -1,9 +1,8 @@ load("@llvm//:http_bsdtar_archive.bzl", http_archive = "http_bsdtar_archive") load("//bazel:http_deb_archive.bzl", "http_deb_archive") -# Local XLA 806111081c build: Intel/FP8 fixes and eager kernel compilation. -_PLUGIN_ONEAPI_URL = "file:///home/steeve/.cache/zml/plugins/zml-oneapi-preload-592f199ad2a8.tar.zst" -_PLUGIN_ONEAPI_SHA256 = "592f199ad2a8a7ee1ac2987b00e96f976f85c10c25a2f5cc4ddbc32e1d6fed67" +_PLUGIN_ONEAPI_URL = "https://mirror.zml.ai/plugins/202611132003.375.1.7d765f57a407/zml-oneapi-linux-amd64.tar.zst" +_PLUGIN_ONEAPI_SHA256 = "294722670832c543c8ac4c074c30f636f2a3b0854820f7c5a070fa82c0d6f3d5" ONEAPI_VERSION = "2026.1" @@ -41,11 +40,6 @@ def _read_packages(mctx, labels): return ret _UBUNTU_PACKAGES = { - "intel-opencl-icd": """ -filegroup( - name = "libigdrcl_so", - srcs = ["lib/x86_64-linux-gnu/intel-opencl/libigdrcl.so"], -)""", "libnl-3-200": """ filegroup( name = "libnl_3", diff --git a/platforms/oneapi/oneapi.zig b/platforms/oneapi/oneapi.zig index e08bbcbd..c5654741 100644 --- a/platforms/oneapi/oneapi.zig +++ b/platforms/oneapi/oneapi.zig @@ -28,7 +28,7 @@ fn hasOneApiDevice(io: std.Io) bool { return false; } -fn setupOneAPIEnv(driver_path: [:0]const u8, opencl_driver_path: [:0]const u8) void { +fn setupOneAPIEnv(driver_path: [:0]const u8) void { _ = c.setenv("CCL_LOG_LEVEL", c.getenv("CCL_LOG_LEVEL") orelse "error", 1); _ = c.setenv("CCL_ATL_TRANSPORT", "ofi", 1); _ = c.setenv("FI_PROVIDER", "shm", 1); @@ -38,8 +38,6 @@ fn setupOneAPIEnv(driver_path: [:0]const u8, opencl_driver_path: [:0]const u8) v _ = c.setenv("XLA_ONECCL_COLLECTIVE_PERMUTE_BYPASS_SYCL_P2P", "1", 1); _ = c.setenv("ONEAPI_DEVICE_SELECTOR", "level_zero:*", 0); _ = c.setenv("ZE_ENABLE_ALT_DRIVERS", driver_path, 0); - // oneDNN also needs the matching OpenCL device for some Level Zero kernels. - _ = c.setenv("OCL_ICD_FILENAMES", opencl_driver_path, 0); } pub fn load(_: std.mem.Allocator, io: std.Io) !*const pjrt.Api { @@ -65,9 +63,7 @@ pub fn load(_: std.mem.Allocator, io: std.Io) !*const pjrt.Api { var driver_path_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; const driver_path = try stdx.Io.Dir.path.bufJoinZ(&driver_path_buf, &.{ sandbox_path, "lib", "libze_intel_gpu.so.1" }); - var opencl_driver_path_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; - const opencl_driver_path = try stdx.Io.Dir.path.bufJoinZ(&opencl_driver_path_buf, &.{ sandbox_path, "lib", "libigdrcl.so" }); - setupOneAPIEnv(driver_path, opencl_driver_path); + setupOneAPIEnv(driver_path); return blk: { var lib_path_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; diff --git a/platforms/oneapi/packages.lock.json b/platforms/oneapi/packages.lock.json index ec9cd263..140ce102 100644 --- a/platforms/oneapi/packages.lock.json +++ b/platforms/oneapi/packages.lock.json @@ -242,17 +242,6 @@ ], "version": "26.31.39395.14-1~24.04~ppa1" }, - { - "arch": "amd64", - "dependencies": [], - "key": "intel-opencl-icd_26.31.39395.14-1_24.04_ppa1_amd64", - "name": "intel-opencl-icd", - "sha256": "6e79028431b03f98a77d0f0ba56750fcef48cdabbe2b0cd8361d9f03cafb9433", - "urls": [ - "https://snapshot.ppa.launchpadcontent.net/kobuk-team/intel-graphics/ubuntu/20260930T000000Z/pool/main/i/intel-compute-runtime/intel-opencl-icd_26.31.39395.14-1~24.04~ppa1_amd64.deb" - ], - "version": "26.31.39395.14-1~24.04~ppa1" - }, { "arch": "amd64", "dependencies": [], diff --git a/platforms/oneapi/packages.yaml b/platforms/oneapi/packages.yaml index d46880d5..5a829ac5 100644 --- a/platforms/oneapi/packages.yaml +++ b/platforms/oneapi/packages.yaml @@ -49,6 +49,5 @@ packages: - "libigc2 (= 2.41.15-1~24.04)" - "libigdfcl2 (= 2.41.15-1~24.04)" - "libze-intel-gpu1 (= 26.31.39395.14-1~24.04~ppa1)" - - "intel-opencl-icd (= 26.31.39395.14-1~24.04~ppa1)" - "libze1" - "zlib1g" diff --git a/zml/BUILD.bazel b/zml/BUILD.bazel index afb83147..f52ecdd5 100644 --- a/zml/BUILD.bazel +++ b/zml/BUILD.bazel @@ -197,9 +197,3 @@ zig_test( name = "test", deps = ["//zml"], ) - -zig_test( - name = "mem_test", - main = "mem_test.zig", - deps = ["//zml"], -) diff --git a/zml/io.zig b/zml/io.zig index d73de04b..ab8d8e6e 100644 --- a/zml/io.zig +++ b/zml/io.zig @@ -340,7 +340,7 @@ pub const Loader = struct { const dma_allocators = try allocator.alloc(mem.DmaAllocator, pool_count); errdefer allocator.free(dma_allocators); for (platform.devices, 0..) |*device, i| { - dma_allocators[i] = .init(std.heap.page_allocator, device); + dma_allocators[i] = .init(allocator, device); } const buffer_pools = try allocator.alloc(mem.DynamicBufferPool, pool_count); diff --git a/zml/mem.zig b/zml/mem.zig index 8df4a736..a64ae968 100644 --- a/zml/mem.zig +++ b/zml/mem.zig @@ -230,6 +230,7 @@ pub const DynamicBufferPool = struct { block_size: usize, max_blocks: usize, + arena_state: std.heap.ArenaAllocator.State = .{}, free_stack: std.atomic.Value(?*Node) = .init(null), in_flight: std.atomic.Value(usize) = .init(0), mutex: std.Io.Mutex = .init, @@ -242,13 +243,8 @@ pub const DynamicBufferPool = struct { }; } - /// All users must have stopped and returned their buffers before teardown. pub fn deinit(self: *DynamicBufferPool, allocator: std.mem.Allocator) void { - assert(self.in_flight.load(.acquire) == 0); - while (self.pop()) |node| { - const buffer: []align(@alignOf(Node)) u8 = @alignCast(self.nodeToSlice(node)); - allocator.free(buffer); - } + self.arena_state.promote(allocator).deinit(); } pub fn get(self: *DynamicBufferPool, allocator: std.mem.Allocator, io: std.Io) ![]u8 { @@ -267,8 +263,12 @@ pub const DynamicBufferPool = struct { self.mutex.lockUncancelable(io); defer self.mutex.unlock(io); + var arena = self.arena_state.promote(allocator); + defer self.arena_state = arena.state; + errdefer _ = self.in_flight.fetchSub(1, .release); - return try allocator.alignedAlloc(u8, alignment, self.block_size); + const buffer = try arena.allocator().alignedAlloc(u8, alignment, self.block_size); + return @alignCast(buffer); } self.mutex.lockUncancelable(io); diff --git a/zml/mem_test.zig b/zml/mem_test.zig deleted file mode 100644 index 24be9e38..00000000 --- a/zml/mem_test.zig +++ /dev/null @@ -1,46 +0,0 @@ -const std = @import("std"); -const Allocator = std.mem.Allocator; - -const zml = @import("zml"); -const DynamicBufferPool = zml.mem.DynamicBufferPool; - -test "DynamicBufferPool reuses and frees buffers" { - const allocator = std.testing.allocator; - const io = std.testing.io; - var pool: DynamicBufferPool = .init(2, 256); - defer pool.deinit(allocator); - - const first_ptr = blk: { - const first = try pool.get(allocator, io); - defer pool.put(io, first); - const second = try pool.get(allocator, io); - defer pool.put(io, second); - try std.testing.expectEqual(@as(usize, 256), first.len); - try std.testing.expect(first.ptr != second.ptr); - @memset(first, 0xa5); - @memset(second, 0x5a); - break :blk first.ptr; - }; - const reused = try pool.get(allocator, io); - defer pool.put(io, reused); - try std.testing.expectEqual(first_ptr, reused.ptr); -} - -test "DynamicBufferPool cleans up allocation failures" { - try std.testing.checkAllAllocationFailures(std.testing.allocator, struct { - fn run(allocator: Allocator) !void { - var pool: DynamicBufferPool = .init(2, 256); - defer pool.deinit(allocator); - const first = pool.get(allocator, std.testing.io) catch |err| { - try std.testing.expectEqual(@as(usize, 0), pool.in_flight.load(.acquire)); - return err; - }; - defer pool.put(std.testing.io, first); - const second = pool.get(allocator, std.testing.io) catch |err| { - try std.testing.expectEqual(@as(usize, 1), pool.in_flight.load(.acquire)); - return err; - }; - defer pool.put(std.testing.io, second); - } - }.run, .{}); -} diff --git a/zml/tensor.zig b/zml/tensor.zig index a09a5d38..ee084835 100644 --- a/zml/tensor.zig +++ b/zml/tensor.zig @@ -282,7 +282,13 @@ pub const Tensor = struct { pub fn toMemory(self: Tensor, kind: Memory.Kind) Tensor { const ctx = Compiler.current(); switch (ctx.platform.target) { - .cpu, .neuron, .metal => return self, + .cpu, .neuron, .metal => { + // A single memory needs no copy, but the result must still be a distinct + // tensor: `reuseBuffer` donations are keyed by tensor id. + var res = _result(self._shape, self.value()); + res._shape._sharding = self._shape._sharding; + return res; + }, .cuda, .rocm, .tpu, .oneapi, .furiosa => {}, }