From d875fc7325444b0c881a82d19671f2a9f502278f Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 25 Sep 2024 12:45:46 +0200 Subject: [PATCH] first steps towards ptx generation --- package/src/Transpiler.jl | 48 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/package/src/Transpiler.jl b/package/src/Transpiler.jl index c4a4591..1162e12 100644 --- a/package/src/Transpiler.jl +++ b/package/src/Transpiler.jl @@ -1,3 +1,6 @@ +module Transpiler +using CUDA +using ..ExpressionProcessing # culoadtest(N, rand(["add.f32", "sub.f32", "mul.f32", "div.approx.f32"])) function culoadtest(N::Int32, op = "add.f32") @@ -73,4 +76,47 @@ function culoadtest(N::Int32, op = "add.f32") blocksPerGrid = (N + threadsPerBlock - 1) รท threadsPerBlock; @time CUDA.@sync cudacall(func, Tuple{CuPtr{Cfloat},CuPtr{Cfloat},CuPtr{Cfloat},Cint}, d_a, d_b, d_c, N; threads=threadsPerBlock, blocks=blocksPerGrid) - end \ No newline at end of file +end + +function transpile(expression::ExpressionProcessing.PostfixType) + +end + +# TODO: Make version, target and address_size configurable +function get_cuda_header()::String + return " + .version 7.1 + .target sm_52 + .address_size 64 + " +end + +function get_kernel_signature(kernelName::String, parameters::Vector{Type})::String + signature = ".visible .entry " * kernelName + + stringBuilder = IOBuffer() + print(stringBuilder, "(") + + for i in eachindex(parameters) + type = type_to_cuda_type(parameters[i]) + print(stringBuilder, + ".param ", type, " ", kernelName, "_param_", i, ",") + end + + print(stringBuilder, ")") + return String(take!(stringBuilder)) +end + +function type_to_cuda_type(type::Type)::String + if type == Int64 + return ".s64" + elseif type == Float64 + return ".f64" + else + return ".b64" + end +end + + +end +