2024-09-28 11:41:13 +02:00
|
|
|
using CUDA
|
|
|
|
using .ExpressionProcessing
|
|
|
|
using .Transpiler
|
|
|
|
|
|
|
|
expressions = Vector{Expr}(undef, 2)
|
2024-11-01 11:23:58 +01:00
|
|
|
variables = Matrix{Float32}(undef, 2,2)
|
|
|
|
parameters = Vector{Vector{Float32}}(undef, 2)
|
2024-09-28 11:41:13 +02:00
|
|
|
|
2024-12-10 22:58:18 +01:00
|
|
|
# Resulting value should be 1.14... for the first expression
|
|
|
|
expressions[1] = :(1 + 3 * 5 / 7 - sqrt(4))
|
2024-09-28 11:41:13 +02:00
|
|
|
expressions[2] = :(5 + x1 + 1 * x2 + p1 + p2)
|
|
|
|
variables[1,1] = 2.0
|
|
|
|
variables[2,1] = 3.0
|
|
|
|
variables[1,2] = 0.0
|
|
|
|
variables[2,2] = 5.0
|
2024-11-01 11:23:58 +01:00
|
|
|
parameters[1] = Vector{Float32}(undef, 1)
|
|
|
|
parameters[2] = Vector{Float32}(undef, 2)
|
2024-09-28 11:41:13 +02:00
|
|
|
parameters[1][1] = 5.0
|
|
|
|
parameters[2][1] = 5.0
|
|
|
|
parameters[2][2] = 0.0
|
|
|
|
|
|
|
|
|
|
|
|
@testset "Test TMP transpiler" begin
|
|
|
|
postfixExpr = expr_to_postfix(expressions[1])
|
|
|
|
postfixExprs = Vector([postfixExpr])
|
|
|
|
push!(postfixExprs, expr_to_postfix(expressions[2]))
|
|
|
|
|
2024-10-26 11:41:00 +02:00
|
|
|
generatedCode = Transpiler.transpile(postfixExpr)
|
2024-09-28 11:41:13 +02:00
|
|
|
# CUDA.@sync interpret(postfixExprs, variables, parameters)
|
2024-10-26 11:41:00 +02:00
|
|
|
|
|
|
|
# This is just here for testing. This will be called inside the execute method in the Transpiler module
|
|
|
|
linker = CuLink()
|
|
|
|
add_data!(linker, "ExpressionProcessing", generatedCode)
|
|
|
|
|
|
|
|
image = complete(linker)
|
|
|
|
|
|
|
|
mod = CuModule(image)
|
|
|
|
func = CuFunction(mod, "ExpressionProcessing")
|
2024-09-28 11:41:13 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
#TODO: test performance of transpiler PTX generation when doing "return String(take!(buffer))" vs "return take!(buffer)"
|