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

This commit is contained in:
2024-08-03 12:11:43 +02:00
parent 6b7a4b4bca
commit f1f8c3b2a4
9 changed files with 188 additions and 175 deletions

View File

@ -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