Skip to content

Commit 16ef0d4

Browse files
lkdvosclaude
andcommitted
Reject the TBLIS backend on Windows and fix the 1.12 constructor warning
The Windows build of tblis_jll aborts the process with "posix_memalign: Invalid argument" out of tblis::MemoryPool::acquire as soon as a contraction reaches the GEMM kernels. The abort does not tear the process down cleanly either, so CI hung until the 6h runner timeout instead of failing. Reject the backend up front on Windows with an ArgumentError that points at StridedBLAS, skip the TBLIS test file there, and document the restriction. Rename the tblis_tensor helper to tblis_tensor_ref: tblis_tensor is a struct in TBLIS, so the method was extending its constructor through an implicit `using` binding, which Julia 1.12 warns about on load. Also cap the CI jobs at 90 minutes so that a native library that aborts or deadlocks fails the job instead of wedging a runner for six hours. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent a753934 commit 16ef0d4

5 files changed

Lines changed: 54 additions & 11 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ jobs:
1717
test:
1818
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
1919
runs-on: ${{ matrix.os }}
20+
# a native library that aborts or deadlocks otherwise wedges the runner for the full
21+
# 6h default; the slowest passing job takes about 45 minutes
22+
timeout-minutes: 90
2023
strategy:
2124
fail-fast: false
2225
matrix:
@@ -49,6 +52,7 @@ jobs:
4952
needs: test
5053
name: Julia nightly - ${{ matrix.os }} - ${{ matrix.arch }}
5154
runs-on: ${{ matrix.os }}
55+
timeout-minutes: 90
5256
strategy:
5357
fail-fast: false
5458
matrix:

‎docs/src/man/backends.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ TBLIS.set_num_threads(8)
8888
TBLIS requires all tensors in a single operation to share one element type out of `Float32`, `Float64`, `ComplexF32` and `ComplexF64`.
8989
Arguments that do not satisfy this, as well as non-strided arrays, are rejected with an `ArgumentError` instead of being passed on to another backend, so that a contraction which cannot actually reach TBLIS is not silently run somewhere else.
9090

91+
The backend is not supported on Windows.
92+
`tblis_jll` does ship a Windows build, but it aborts the process from inside the library as soon as a contraction reaches its GEMM kernels, so calls there are rejected with an `ArgumentError` instead.
93+
9194
Note that contracting in place trades throughput for memory rather than being a free win.
9295
With BLAS, TBLIS and `Strided.jl` all given the same number of threads, this backend is roughly on par with `StridedBLAS` for permuted real contractions and slower for other shapes, while allocating no permuted temporaries at all.
9396

‎ext/TensorOperationsTBLISExt.jl‎

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ const SV = StridedView
1717

1818
const TBLISFloat = Union{Float32, Float64, ComplexF32, ComplexF64}
1919

20+
# `tblis_jll` does ship a Windows build, but it aborts the process with
21+
# "posix_memalign: Invalid argument" from `tblis::MemoryPool::acquire` as soon as a
22+
# contraction reaches the GEMM kernels, so nothing is handed to the library there.
23+
const PLATFORM_SUPPORTED = !Sys.iswindows()
24+
2025
#-------------------------------------------------------------------------------------------
2126
# Wrapping Julia arrays as TBLIS tensors
2227
#-------------------------------------------------------------------------------------------
@@ -38,7 +43,7 @@ isconj(A::StridedView{T}, conjA::Bool) where {T} = T <: Complex && (conjA ⊻ (A
3843
tblis_dims(A::StridedView) = (collect(len_type, size(A)), collect(stride_type, strides(A)))
3944

4045
"""
41-
tblis_tensor(A::StridedView, α, len, stride, conj) -> Ref{TBLIS.tblis_tensor}
46+
tblis_tensor_ref(A::StridedView, α, len, stride, conj) -> Ref{TBLIS.tblis_tensor}
4247
4348
Descriptor for `α * A`, conjugated when `conj` is set, using `len` and `stride` as the
4449
buffers handed to TBLIS.
@@ -48,7 +53,7 @@ with the returned `Ref`, have to be kept alive by the caller for as long as TBLI
4853
them. Note that `conj` is the *total* conjugation applied to the data of `A`, as computed by
4954
[`isconj`](@ref), not the flag the caller was handed.
5055
"""
51-
function tblis_tensor(
56+
function tblis_tensor_ref(
5257
A::StridedView{T, N}, α::T,
5358
len::Vector{len_type}, stride::Vector{stride_type}, conj::Bool
5459
) where {T <: TBLISFloat, N}
@@ -66,6 +71,18 @@ labels(ein::Tuple{Vararg{Char}}) = String(UInt8[c for c in ein])
6671
#-------------------------------------------------------------------------------------------
6772
# Argument checking
6873
#-------------------------------------------------------------------------------------------
74+
@noinline function throw_unsupported_platform(f)
75+
return throw(
76+
ArgumentError(
77+
LazyString(
78+
"TBLISBackend is not supported on ", Base.BUILD_TRIPLET, ": the tblis_jll ",
79+
"binaries for this platform abort the process from inside the library. ",
80+
"Use another backend, such as StridedBLAS(), for ", f
81+
)
82+
)
83+
)
84+
end
85+
6986
@noinline function throw_eltype(f, tensors)
7087
return throw(
7188
ArgumentError(
@@ -88,6 +105,7 @@ end
88105
)
89106

90107
function check_arguments(f, C::AbstractArray, As::AbstractArray...)
108+
PLATFORM_SUPPORTED || throw_unsupported_platform(f)
91109
tensors = (C, As...)
92110
T = eltype(C)
93111
(T <: TBLISFloat && all(A -> eltype(A) === T, As)) || throw_eltype(f, tensors)
@@ -118,8 +136,8 @@ function TO.tensoradd!(
118136
lenA, strideA = tblis_dims(Av)
119137
lenC, strideC = tblis_dims(Cv)
120138
GC.@preserve Av Cv lenA strideA lenC strideC begin
121-
tA = tblis_tensor(Av, convert(T, α), lenA, strideA, isconj(Av, conjA))
122-
tC = tblis_tensor(Cv, convert(T, β), lenC, strideC, false)
139+
tA = tblis_tensor_ref(Av, convert(T, α), lenA, strideA, isconj(Av, conjA))
140+
tC = tblis_tensor_ref(Cv, convert(T, β), lenC, strideC, false)
123141
TBLIS.tblis_tensor_add(C_NULL, C_NULL, tA, labels(einA), tC, labels(einC))
124142
end
125143
return C
@@ -143,8 +161,8 @@ function TO.tensortrace!(
143161
lenA, strideA = tblis_dims(Av)
144162
lenC, strideC = tblis_dims(Cv)
145163
GC.@preserve Av Cv lenA strideA lenC strideC begin
146-
tA = tblis_tensor(Av, convert(T, α), lenA, strideA, isconj(Av, conjA))
147-
tC = tblis_tensor(Cv, convert(T, β), lenC, strideC, false)
164+
tA = tblis_tensor_ref(Av, convert(T, α), lenA, strideA, isconj(Av, conjA))
165+
tC = tblis_tensor_ref(Cv, convert(T, β), lenC, strideC, false)
148166
TBLIS.tblis_tensor_add(C_NULL, C_NULL, tA, labels(einA), tC, labels(einC))
149167
end
150168
return C
@@ -199,9 +217,9 @@ function tblis_mult!(
199217
lenB, strideB = tblis_dims(B)
200218
lenC, strideC = tblis_dims(C)
201219
GC.@preserve A B C lenA strideA lenB strideB lenC strideC begin
202-
tA = tblis_tensor(A, α, lenA, strideA, false)
203-
tB = tblis_tensor(B, one(T), lenB, strideB, false)
204-
tC = tblis_tensor(C, β, lenC, strideC, false)
220+
tA = tblis_tensor_ref(A, α, lenA, strideA, false)
221+
tB = tblis_tensor_ref(B, one(T), lenB, strideB, false)
222+
tC = tblis_tensor_ref(C, β, lenC, strideC, false)
205223
TBLIS.tblis_tensor_mult(
206224
C_NULL, C_NULL, tA, labels(einA), tB, labels(einB), tC, labels(einC)
207225
)

‎src/backends.jl‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ has to be one of `Float32`, `Float64`, `ComplexF32` or `ComplexF64`.
8888
Arguments that do not meet these requirements, including non-strided arrays, are rejected
8989
with an `ArgumentError` rather than passed on to another backend.
9090
91+
!!! warning
92+
This backend is not supported on Windows: the `tblis_jll` binaries for that platform
93+
abort the process from inside the library, so calls are rejected with an
94+
`ArgumentError` there as well.
95+
9196
!!! note
9297
Contracting in place trades throughput for memory.
9398
On a 16-core node this backend is roughly on par with

‎test/runtests.jl‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,21 @@ if !is_buildkite
8181
include("butensor.jl")
8282
end
8383

84-
@testset "TBLIS extension" verbose = true begin
85-
include("tblis.jl")
84+
if Sys.iswindows()
85+
# the Windows build of `tblis_jll` aborts the process from inside the library, so
86+
# the extension refuses to call into it and there is nothing else to test
87+
using TBLIS
88+
@testset "TBLIS extension (unsupported platform)" begin
89+
A = randn(Float64, (3, 4))
90+
@test_throws ArgumentError tensoradd!(
91+
zeros(Float64, (4, 3)), A, ((2, 1), ()), false, 1, 0,
92+
TensorOperations.TBLISBackend()
93+
)
94+
end
95+
else
96+
@testset "TBLIS extension" verbose = true begin
97+
include("tblis.jl")
98+
end
8699
end
87100

88101
@testset "Polynomials" begin

0 commit comments

Comments
 (0)