first simple part of the interpreter finished
Some checks failed
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.10) (push) Has been cancelled
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.6) (push) Has been cancelled
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, pre) (push) Has been cancelled
Some checks failed
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.10) (push) Has been cancelled
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.6) (push) Has been cancelled
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, pre) (push) Has been cancelled
This commit is contained in:
@ -5,6 +5,7 @@ version = "1.0.0-DEV"
|
||||
|
||||
[deps]
|
||||
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
|
||||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
|
||||
|
||||
[compat]
|
||||
julia = "1.6.7"
|
||||
|
@ -3,11 +3,11 @@ module ExpressionProcessing
|
||||
export expr_to_postfix
|
||||
export PostfixType
|
||||
export Operator, ADD, SUBTRACT, MULTIPLY, DIVIDE, POWER, ABS, LOG, EXP, SQRT
|
||||
export ElementType, EMPTY, FLOAT64, OPERATOR, INT64
|
||||
export ElementType, EMPTY, FLOAT64, OPERATOR, INDEX
|
||||
export ExpressionElement
|
||||
|
||||
@enum Operator::Int64 ADD=1 SUBTRACT=2 MULTIPLY=3 DIVIDE=4 POWER=5 ABS=6 LOG=7 EXP=8 SQRT=9
|
||||
@enum ElementType EMPTY=0 FLOAT64=1 OPERATOR=2 INT64=3
|
||||
@enum ElementType EMPTY=0 FLOAT64=1 OPERATOR=2 INDEX=3
|
||||
|
||||
struct ExpressionElement
|
||||
Type::ElementType
|
||||
@ -84,7 +84,7 @@ function convert_to_ExpressionElement(element)::ExpressionElement
|
||||
if element isa Float64
|
||||
return ExpressionElement(FLOAT64, Value)
|
||||
elseif element isa Int64
|
||||
return ExpressionElement(INT64, Value)
|
||||
return ExpressionElement(INDEX, Value)
|
||||
elseif element isa Operator
|
||||
return ExpressionElement(OPERATOR, Value)
|
||||
else
|
||||
|
@ -1,5 +1,6 @@
|
||||
module Interpreter
|
||||
using CUDA
|
||||
using StaticArrays
|
||||
using ..ExpressionProcessing
|
||||
|
||||
export interpret
|
||||
@ -20,7 +21,6 @@ function interpret(expressions::Vector{ExpressionProcessing.PostfixType}, variab
|
||||
cudaExprs = create_cuda_array(expressions, ExpressionElement(EMPTY, 0)) # column corresponds to data for one expression
|
||||
cudaStepsize = CuArray([get_max_inner_length(expressions), get_max_inner_length(parameters)]) # put into seperate cuArray, as this is static and would be inefficient to send seperatly to every kernel
|
||||
|
||||
println(cudaVars)
|
||||
# Start kernel for each expression to ensure that no warp is working on different expressions
|
||||
for i in eachindex(expressions)
|
||||
kernel = @cuda launch=false interpret_expression(cudaExprs, cudaVars, cudaParams, cudaStepsize, i)
|
||||
@ -28,27 +28,41 @@ function interpret(expressions::Vector{ExpressionProcessing.PostfixType}, variab
|
||||
threads = min(variableRows, config.threads)
|
||||
blocks = cld(variableRows, threads)
|
||||
|
||||
# TODO: Operation stack should be n-dims. nr. of Rows == length of this expression
|
||||
# nr. of columns == nr. of rows in Vars
|
||||
# This means every run with different variable set has its own stack
|
||||
# cudaOperationStack = CuArray{Float64}(undef, get_max_inner_length(expressions), length(expressions))
|
||||
|
||||
kernel(cudaExprs, cudaVars, cudaParams, cudaStepsize, i; threads, blocks)
|
||||
end
|
||||
end
|
||||
|
||||
const MAX_STACK_SIZE = 25 # The max number of values the expression can have. so Constant values, Variables and parameters
|
||||
function interpret_expression(expressions::CuDeviceArray{ExpressionElement}, variables::CuDeviceArray{Float64}, parameters::CuDeviceArray{Float64}, stepsize::CuDeviceArray{Int}, exprIndex::Int)
|
||||
firstExprIndex = ((exprIndex - 1) * stepsize[1]) + 1 # Inclusive
|
||||
lastExprIndex = firstExprIndex + stepsize[1] - 1 # Inclusive
|
||||
firstParamIndex = ((exprIndex - 1) * stepsize[2]) + 1 # Inclusive
|
||||
firstParamIndex = ((exprIndex - 1) * stepsize[2]) # Exclusive
|
||||
# lastParamIndex = firstParamIndex + stepsize[2] - 1 # Inclusive (probably not needed)
|
||||
operationStack = MVector{MAX_STACK_SIZE, Float64}(undef) # Vector{Float64}(undef, MAX_STACK_SIZE) # Try to get this to function with variable size too
|
||||
operationStackTop = 1
|
||||
|
||||
for i in reverse(firstExprIndex:lastExprIndex) # Calculate real "lastExprIndex"
|
||||
if expressions[i].Type != EMPTY
|
||||
lastExprIndex = i
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
for i in 1:5
|
||||
@cuprintln(variables[i])
|
||||
end
|
||||
|
||||
# Not the correct approach. Redo this to be more stack based.
|
||||
return
|
||||
|
||||
for i in firstExprIndex:lastExprIndex
|
||||
# TODO Implement interpreter
|
||||
# - start at firstExprIndex and interpret until the first ExpressionElement is "Empty" or we reached lastExprIndex
|
||||
if expressions[i].Type == EMPTY
|
||||
break
|
||||
elseif expressions[i].Type == INT64
|
||||
elseif expressions[i].Type == INDEX
|
||||
# TODO: Load value from variables/parameters matrix and store for calculation
|
||||
val = expressions[i].Value
|
||||
|
||||
@ -56,14 +70,14 @@ function interpret_expression(expressions::CuDeviceArray{ExpressionElement}, var
|
||||
# TODO: access variables
|
||||
else
|
||||
val = abs(val)
|
||||
# TODO: access parameters
|
||||
operationStack[operationStackTop] = parameters[firstParamIndex + val]
|
||||
end
|
||||
continue
|
||||
operationStackTop += 1
|
||||
elseif expressions[i].Type == FLOAT64
|
||||
# TODO: store value as is for calculation
|
||||
continue
|
||||
operationStack[operationStackTop] = expressions[i].Value
|
||||
operationStackTop += 1
|
||||
elseif expressions[i].Type == OPERATOR
|
||||
# TODO: Perform calculation of the two stored values according to the operator
|
||||
# TODO: Perform calculation of the stored values. Either 1 or 2, depending on the operator
|
||||
continue
|
||||
else
|
||||
# TODO: handle this case. Should not happen but in case it does, it needs to do something
|
||||
|
@ -13,7 +13,7 @@ parameters[1][1] = 5
|
||||
|
||||
@testset "Test conversion expression element" begin
|
||||
reference1 = ExpressionElement(FLOAT64, reinterpret(Int64, 1.0))
|
||||
reference2 = ExpressionElement(INT64, reinterpret(Int64, 1))
|
||||
reference2 = ExpressionElement(INDEX, reinterpret(Int64, 1))
|
||||
reference3 = ExpressionElement(OPERATOR, reinterpret(Int64, ADD))
|
||||
|
||||
@test isequal(reference1, ExpressionProcessing.convert_to_ExpressionElement(1.0))
|
||||
|
@ -10,8 +10,8 @@ parameters = Vector{Vector{Float64}}(undef, 2)
|
||||
expressions[1] = :(x1 + 1 * x2 + p1)
|
||||
expressions[2] = :(5 + x1 + 1 * x2 + p1 + p2)
|
||||
variables[1,1] = 2.0
|
||||
variables[1,2] = 3.0
|
||||
variables[2,1] = 0.0
|
||||
variables[2,1] = 3.0
|
||||
variables[1,2] = 0.0
|
||||
variables[2,2] = 5.0
|
||||
parameters[1] = Vector{Float64}(undef, 1)
|
||||
parameters[2] = Vector{Float64}(undef, 2)
|
||||
|
@ -1,3 +1,4 @@
|
||||
[deps]
|
||||
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
|
||||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
|
||||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||
|
Reference in New Issue
Block a user