Getting Started
Installation
Install Julia v1.10 or above. Reactant.jl is available through the Julia package manager. You can enter it by pressing ] in the REPL and then typing add Reactant. Alternatively, you can also do
import Pkg
Pkg.add("Reactant")Quick Start
Reactant provides two new array types at its core, a ConcreteRArray and a TracedRArray. A ConcreteRArray is an underlying buffer to whatever device data you wish to store and can be created by converting from a regular Julia Array.
using Reactant
julia_data = ones(2, 10)
reactant_data = Reactant.ConcreteRArray(julia_data)2×10 ConcretePJRTArray{Float64,2}:
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0You can also create a ConcreteRArray-version of an arbitrary data type by tracing through the structure, like below.
struct Pair{A,B}
x::A
y::B
end
pair = Pair(ones(3), ones(10))
reactant_pair = Reactant.to_rarray(pair)Main.Pair{ConcretePJRTArray{Float64, 1, 1}, ConcretePJRTArray{Float64, 1, 1}}(ConcretePJRTArray{Float64, 1, 1}([1.0, 1.0, 1.0]), ConcretePJRTArray{Float64, 1, 1}([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]))Tracking scalar numbers
By default, Reactant.to_rarray only converts arrays — plain Julia numbers are left as-is and treated as compile-time constants. If you need scalar values to vary at runtime (e.g. a time parameter t), use track_numbers=true:
t = Reactant.to_rarray(1.5; track_numbers=true) # ConcreteRNumber{Float64}See the Partial Evaluation tutorial for details.
To compile programs using ConcreteRArray's, one uses the compile function, like as follows:
input1 = Reactant.ConcreteRArray(ones(10))
input2 = Reactant.ConcreteRArray(ones(10))
function sinsum_add(x, y)
return sum(sin.(x) .+ y)
end
f = @compile sinsum_add(input1,input2)
# one can now run the program
f(input1, input2)ConcretePJRTNumber{Float64, 1}(18.414709848078964)