added first (wrong) attempt at implementing the interpretation. Added input explanation to the readme for a better understanding
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-07-24 14:42:26 +02:00
parent c871487a55
commit 6b7a4b4bca
5 changed files with 558 additions and 10 deletions

View File

@ -13,12 +13,14 @@ export interpret
function interpret(expressions::Vector{ExpressionProcessing.PostfixType}, variables::Matrix{Float64}, parameters::Vector{Vector{Float64}})
# TODO:
# create CUDA array for calculation results
variableRows = size(variables, 1)
cudaVars = CuArray(variables)
cudaParams = create_cuda_array(parameters, NaN64)
cudaExprs = create_cuda_array(expressions, ExpressionElement(EMPTY, 0))
cudaParams = create_cuda_array(parameters, NaN64) # column corresponds to data for one expression
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)
@ -31,16 +33,45 @@ function interpret(expressions::Vector{ExpressionProcessing.PostfixType}, variab
end
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] # Exclusive
firstParamIndex = (exprIndex - 1 * stepsize[2]) + 1 # Inclusive
# lastParamIndex = firstParamIndex + stepsize[2] # Exclusive (probably not needed)
firstExprIndex = ((exprIndex - 1) * stepsize[1]) + 1 # Inclusive
lastExprIndex = firstExprIndex + stepsize[1] - 1 # Inclusive
firstParamIndex = ((exprIndex - 1) * stepsize[2]) + 1 # Inclusive
# lastParamIndex = firstParamIndex + stepsize[2] - 1 # Inclusive (probably not needed)
for i in 1:5
@cuprintln(variables[i])
end
# Not the correct approach. Redo this to be more stack based.
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
# TODO: Load value from variables/parameters matrix and store for calculation
val = expressions[i].Value
if val > 0
# TODO: access variables
else
val = abs(val)
# TODO: access parameters
end
continue
elseif expressions[i].Type == FLOAT64
# TODO: store value as is for calculation
continue
elseif expressions[i].Type == OPERATOR
# TODO: Perform calculation of the two stored values according to the operator
continue
else
# TODO: handle this case. Should not happen but in case it does, it needs to do something
continue
end
end
# TODO: Store computed value in output matrix
return
end