started implementing parameter loading
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:
parent
f7926c3438
commit
219c0bb14e
|
@ -26,22 +26,23 @@ using ..ExpressionProcessing
|
||||||
const Operand = Union{Float32, String} # Operand is either fixed value or register
|
const Operand = Union{Float32, String} # Operand is either fixed value or register
|
||||||
|
|
||||||
# To increase performance, it would probably be best for all helper functions to return their IO Buffer and not a string
|
# To increase performance, it would probably be best for all helper functions to return their IO Buffer and not a string
|
||||||
|
# seekstart(buf1); write(buf2, buf1)
|
||||||
function transpile(expression::ExpressionProcessing.PostfixType)::String
|
function transpile(expression::ExpressionProcessing.PostfixType)::String
|
||||||
exitJumpLocationMarker = "\$L__BB0_2"
|
exitJumpLocationMarker = "\$L__BB0_2"
|
||||||
ptxBuffer = IOBuffer()
|
ptxBuffer = IOBuffer()
|
||||||
|
|
||||||
|
# TODO: Suboptimal solution
|
||||||
|
signature, paramLoading = get_kernel_signature("ExpressionProcessing", [Int32, Int32, Float32]) # nrOfVarSets, nrOfVarsPerSet, Vars
|
||||||
|
guardClause = get_guard_clause(exitJumpLocationMarker, "%parameter0") # r0 because first entry holds the number of variables and that is always stored in %r0
|
||||||
|
|
||||||
println(ptxBuffer, get_cuda_header())
|
println(ptxBuffer, get_cuda_header())
|
||||||
println(ptxBuffer, get_kernel_signature("ExpressionProcessing", [Int32, Float32]))
|
println(ptxBuffer, signature)
|
||||||
println(ptxBuffer, "{")
|
println(ptxBuffer, "{")
|
||||||
|
|
||||||
# TODO: Parameter loading
|
|
||||||
|
|
||||||
# TODO: once parameters are loaded, the second parameter for the guard clause can be set
|
calc_code = generate_calculation_code(expression, "%parameter2")
|
||||||
temp = get_next_free_register("r")
|
|
||||||
guardClause = get_guard_clause(exitJumpLocationMarker, temp) # since we need to know how many registers we used, we cannot yet write the guard clause to the ptxBuffer
|
|
||||||
|
|
||||||
calc_code = generate_calculation_code(expression)
|
|
||||||
println(ptxBuffer, get_register_definitions())
|
println(ptxBuffer, get_register_definitions())
|
||||||
|
println(ptxBuffer, paramLoading)
|
||||||
println(ptxBuffer, guardClause)
|
println(ptxBuffer, guardClause)
|
||||||
println(ptxBuffer, calc_code)
|
println(ptxBuffer, calc_code)
|
||||||
|
|
||||||
|
@ -58,29 +59,31 @@ end
|
||||||
function get_cuda_header()::String
|
function get_cuda_header()::String
|
||||||
return "
|
return "
|
||||||
.version 7.1
|
.version 7.1
|
||||||
.target sm_52
|
.target sm_61
|
||||||
.address_size 64
|
.address_size 64
|
||||||
"
|
"
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_kernel_signature(kernelName::String, parameters::Vector{DataType})::String
|
function get_kernel_signature(kernelName::String, parameters::Vector{DataType})::Tuple{String, String}
|
||||||
signatureBuffer = IOBuffer()
|
signatureBuffer = IOBuffer()
|
||||||
|
paramLoadingBuffer = IOBuffer()
|
||||||
print(signatureBuffer, ".visible .entry ")
|
print(signatureBuffer, ".visible .entry ")
|
||||||
print(signatureBuffer, kernelName)
|
print(signatureBuffer, kernelName)
|
||||||
println(signatureBuffer, "(")
|
println(signatureBuffer, "(")
|
||||||
|
|
||||||
|
|
||||||
for i in eachindex(parameters)
|
for i in eachindex(parameters)
|
||||||
type = type_to_ptx_type(parameters[i])
|
print(signatureBuffer, " .param .u32", " ", "param_", i)
|
||||||
print(signatureBuffer,
|
|
||||||
" .param ", type, " ", kernelName, "_param_", i)
|
parameterRegister = get_next_free_register("r")
|
||||||
|
println(paramLoadingBuffer, "ld.param.u32 $parameterRegister, [param_$i];")
|
||||||
|
println(paramLoadingBuffer, "cvta.to.global.u32 $(get_next_free_register("parameter")), $parameterRegister;")
|
||||||
if i != lastindex(parameters)
|
if i != lastindex(parameters)
|
||||||
println(signatureBuffer, ",")
|
println(signatureBuffer, ",")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print(signatureBuffer, ")")
|
print(signatureBuffer, ")")
|
||||||
return String(take!(signatureBuffer))
|
return (String(take!(signatureBuffer)), String(take!(paramLoadingBuffer)))
|
||||||
end
|
end
|
||||||
|
|
||||||
"
|
"
|
||||||
|
@ -102,8 +105,10 @@ function get_guard_clause(exitJumpLocation::String, nrOfVarSetsRegister::String)
|
||||||
|
|
||||||
globalThreadId = get_next_free_register("r") # basically the index of the thread in the variable set
|
globalThreadId = get_next_free_register("r") # basically the index of the thread in the variable set
|
||||||
breakCondition = get_next_free_register("p")
|
breakCondition = get_next_free_register("p")
|
||||||
println(guardBuffer, "mad.lo.s32 $globalThreadId, $threadIds, $threadsPerCTA, $currentThreadId;")
|
nrOfVarSets = get_next_free_register("i")
|
||||||
println(guardBuffer, "setp.ge.s32 $breakCondition, $globalThreadId, $nrOfVarSetsRegister;") # guard clause = index > nrOfVariableSets
|
println(guardBuffer, "ld.global.u32 $nrOfVarSets, $nrOfVarSetsRegister;")
|
||||||
|
println(guardBuffer, "mad.lo.s32 $globalThreadId, $threadIds, $threadsPerCTA, $currentThreadId;")
|
||||||
|
println(guardBuffer, "setp.ge.s32 $breakCondition, $globalThreadId, $nrOfVarSets;") # guard clause = index > nrOfVariableSets
|
||||||
|
|
||||||
# branch to end if breakCondition is true
|
# branch to end if breakCondition is true
|
||||||
print(guardBuffer, "@$breakCondition bra $exitJumpLocation;")
|
print(guardBuffer, "@$breakCondition bra $exitJumpLocation;")
|
||||||
|
@ -111,12 +116,10 @@ function get_guard_clause(exitJumpLocation::String, nrOfVarSetsRegister::String)
|
||||||
return String(take!(guardBuffer))
|
return String(take!(guardBuffer))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Current assumption: Expression only made out of constant values
|
function generate_calculation_code(expression::ExpressionProcessing.PostfixType, variablesRegister::String)::String
|
||||||
function generate_calculation_code(expression::ExpressionProcessing.PostfixType)::String
|
|
||||||
codeBuffer = IOBuffer()
|
codeBuffer = IOBuffer()
|
||||||
operands = Vector{Operand}()
|
operands = Vector{Operand}()
|
||||||
|
|
||||||
println(expression)
|
|
||||||
for i in eachindex(expression)
|
for i in eachindex(expression)
|
||||||
token = expression[i]
|
token = expression[i]
|
||||||
|
|
||||||
|
@ -138,6 +141,13 @@ function generate_calculation_code(expression::ExpressionProcessing.PostfixType)
|
||||||
push!(operands, resultRegister)
|
push!(operands, resultRegister)
|
||||||
elseif token.Type == INDEX
|
elseif token.Type == INDEX
|
||||||
# TODO
|
# TODO
|
||||||
|
# %parameter1 + startIndex + Index * bytes
|
||||||
|
# startIndex: should be calculateable by global threadId and size of variables
|
||||||
|
if token.Value > 0 # varaibles
|
||||||
|
var = get_next_free_register("f")
|
||||||
|
#TODO: investigate how best to load var from global to local memory, especially when var used multiple times. (probably kind of symtable)
|
||||||
|
push!(operands, "[$variablesRegister+$(token.Value*sizeof(token.Value))]") # missing: startIndex
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -147,6 +157,8 @@ end
|
||||||
function type_to_ptx_type(type::DataType)::String
|
function type_to_ptx_type(type::DataType)::String
|
||||||
if type == Int64
|
if type == Int64
|
||||||
return ".s64"
|
return ".s64"
|
||||||
|
elseif type == Int32
|
||||||
|
return ".s32"
|
||||||
elseif type == Float32
|
elseif type == Float32
|
||||||
return ".f32"
|
return ".f32"
|
||||||
else
|
else
|
||||||
|
@ -231,6 +243,10 @@ let registers = Dict() # stores the count of the register already used.
|
||||||
regType = ".f32"
|
regType = ".f32"
|
||||||
elseif definition.first == "r"
|
elseif definition.first == "r"
|
||||||
regType = ".b32"
|
regType = ".b32"
|
||||||
|
elseif definition.first == "parameter"
|
||||||
|
regType = ".u32"
|
||||||
|
elseif definition.first == "i"
|
||||||
|
regType = ".u32"
|
||||||
else
|
else
|
||||||
throw(ArgumentError("Unknown register name used. Name '$(definition.first)' cannot be mapped to a PTX type."))
|
throw(ArgumentError("Unknown register name used. Name '$(definition.first)' cannot be mapped to a PTX type."))
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,7 @@ parameters[2][2] = 0.0
|
||||||
postfixExpr = expr_to_postfix(expressions[1])
|
postfixExpr = expr_to_postfix(expressions[1])
|
||||||
postfixExprs = Vector([postfixExpr])
|
postfixExprs = Vector([postfixExpr])
|
||||||
push!(postfixExprs, expr_to_postfix(expressions[2]))
|
push!(postfixExprs, expr_to_postfix(expressions[2]))
|
||||||
push!(postfixExprs, expr_to_postfix(:(5^3)))
|
push!(postfixExprs, expr_to_postfix(:(5^3 + x1)))
|
||||||
|
|
||||||
# generatedCode = Transpiler.transpile(postfixExpr)
|
# generatedCode = Transpiler.transpile(postfixExpr)
|
||||||
generatedCode = Transpiler.transpile(postfixExprs[3]) # TEMP
|
generatedCode = Transpiler.transpile(postfixExprs[3]) # TEMP
|
||||||
|
|
Loading…
Reference in New Issue
Block a user