You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to use Reactant with KernelAbstractions (on CPU for now). This code:
using KernelAbstractions
using Random
using Reactant
using CUDA
const backend =CPU() #CUDA.CUDABackend(; always_inline=true)
Reactant.allowscalar(true)
# Simple kernel for matrix multiplication@kernelfunctionmatmul_kernel!(output, a, b)
i, j =@index(Global, NTuple)
# creating a temporary sum variable for matrix multiplication
tmp_sum =zero(eltype(output))
@tracefor k in1:size(a)[2]
tmp_sum +=@inbounds a[i, k] * b[k, j]
end@inbounds output[i, j] = tmp_sum
end# Creating a wrapper kernel for launching with error checksfunctionmatmul!(output, a, b)
ifsize(a)[2] !=size(b)[1]
println("Matrix size mismatch!")
returnnothingend#backend = KernelAbstractions.get_backend(a)
kernel! =matmul_kernel!(backend)
kernel!(output, a, b, ndrange =size(output))
end
a =rand!(allocate(backend, Float32, 256, 123))
b =rand!(allocate(backend, Float32, 123, 45))
output = KernelAbstractions.zeros(backend, Float32, 256, 45)
matmul!(output, a, b)
KernelAbstractions.synchronize(backend)
@showisapprox(output, a * b)
ra = Reactant.to_rarray(a)
rb = Reactant.to_rarray(b)
ro = Reactant.to_rarray(output)
if CUDA.functional()
@jitmatmul!(ro, ra, rb)
@showall(Array(ro) .≈ output)
else@code_hlo optimize =:before_kernelmatmul!(ro, ra, rb)
end
produces
julia> include("reactant_kernels.jl")
ERROR: LoadError: UndefVarError: `pop` not defined
Stacktrace:
[1] macro expansion
@ ~/.julia/packages/ReactantCore/Lh7r5/src/ReactantCore.jl:185 [inlined]
[2] macro expansion
@ ~/Projects/Enzymantics/Enzymanigans.jl/reactant_kernels.jl:16 [inlined]
[3] cpu_matmul_kernel!
@ ~/.julia/packages/KernelAbstractions/0r40T/src/macros.jl:293 [inlined]
[4] cpu_matmul_kernel!(__ctx__::KernelAbstractions.CompilerMetadata{…}, output::Matrix{…}, a::Matrix{…}, b::Matrix{…})
@ Main ./none:0
[5] __thread_run(tid::Int64, len::Int64, rem::Int64, obj::KernelAbstractions.Kernel{…}, ndrange::Tuple{…}, iterspace::KernelAbstractions.NDIteration.NDRange{…}, args::Tuple{…}, dynamic::KernelAbstractions.NDIteration.DynamicCheck)
@ KernelAbstractions ~/.julia/packages/KernelAbstractions/0r40T/src/cpu.jl:142
[6] __run(obj::KernelAbstractions.Kernel{…}, ndrange::Tuple{…}, iterspace::KernelAbstractions.NDIteration.NDRange{…}, args::Tuple{…}, dynamic::KernelAbstractions.NDIteration.DynamicCheck, static_threads::Bool)
@ KernelAbstractions ~/.julia/packages/KernelAbstractions/0r40T/src/cpu.jl:109
[7] (::KernelAbstractions.Kernel{…})(::Matrix{…}, ::Vararg{…}; ndrange::Tuple{…}, workgroupsize::Nothing)
@ KernelAbstractions ~/.julia/packages/KernelAbstractions/0r40T/src/cpu.jl:44
[8] Kernel
@ ~/.julia/packages/KernelAbstractions/0r40T/src/cpu.jl:37 [inlined]
[9] matmul!(output::Matrix{Float32}, a::Matrix{Float32}, b::Matrix{Float32})
@ Main ~/Projects/Enzymantics/Enzymanigans.jl/reactant_kernels.jl:31
[10] top-level scope
@ ~/Projects/Enzymantics/Enzymanigans.jl/reactant_kernels.jl:38
[11] include(fname::String)
@ Base.MainInclude ./client.jl:494
[12] top-level scope
@ REPL[1]:1
in expression starting at /Users/gregorywagner/Projects/Enzymantics/Enzymanigans.jl/reactant_kernels.jl:38
Some type information was truncated. Use `show(err)` to see complete types.
The text was updated successfully, but these errors were encountered:
Trying to use Reactant with KernelAbstractions (on CPU for now). This code:
produces
The text was updated successfully, but these errors were encountered: