From 5acfd6ff728402239f5a9458f3c514eba3ae5947 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Fri, 23 Jun 2023 16:47:48 +0200 Subject: [PATCH] Update to LLVM.jl 6. (#334) --- Manifest.toml | 24 ++++++++++++------------ Project.toml | 2 +- src/compiler/compilation.jl | 16 ++++++---------- src/device/opencl/memory.jl | 10 +++++----- src/device/opencl/printf.jl | 14 +++++++------- 5 files changed, 31 insertions(+), 35 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index e102a868..3271d071 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -40,9 +40,9 @@ version = "0.1.7" [[Compat]] deps = ["Dates", "LinearAlgebra", "UUIDs"] -git-tree-sha1 = "7a60c856b9fa189eb34f5f8a6f6b5529b7942957" +git-tree-sha1 = "4e88377ae7ebeaf29a047aa1ee40826e0b708a5d" uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "4.6.1" +version = "4.7.0" [[CompilerSupportLibraries_jll]] deps = ["Artifacts", "Libdl"] @@ -69,9 +69,9 @@ version = "0.1.9" [[GPUArrays]] deps = ["Adapt", "GPUArraysCore", "LLVM", "LinearAlgebra", "Printf", "Random", "Reexport", "Serialization", "Statistics"] -git-tree-sha1 = "a3351bc577a6b49297248aadc23a4add1097c2ac" +git-tree-sha1 = "2e57b4a4f9cc15e85a24d603256fe08e527f48d1" uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7" -version = "8.7.1" +version = "8.8.1" [[GPUArraysCore]] deps = ["Adapt"] @@ -81,9 +81,9 @@ version = "0.1.5" [[GPUCompiler]] deps = ["ExprTools", "InteractiveUtils", "LLVM", "Libdl", "Logging", "Scratch", "TimerOutputs", "UUIDs"] -git-tree-sha1 = "c47730aca2381f935a52fd732190e424c507230e" +git-tree-sha1 = "0c21d9b7ff70859bdb2ca7dab814e144676c31db" uuid = "61eb1bfa-7361-4325-ad38-22787b887f55" -version = "0.21.0" +version = "0.21.1" [[InteractiveUtils]] deps = ["Markdown"] @@ -108,15 +108,15 @@ version = "1.4.1" [[KernelAbstractions]] deps = ["Adapt", "Atomix", "InteractiveUtils", "LinearAlgebra", "MacroTools", "PrecompileTools", "SparseArrays", "StaticArrays", "UUIDs", "UnsafeAtomics", "UnsafeAtomicsLLVM"] -git-tree-sha1 = "47be64f040a7ece575c2b5f53ca6da7b548d69f4" +git-tree-sha1 = "b48617c5d764908b5fac493cd907cf33cc11eec1" uuid = "63c18a36-062a-441e-b654-da1e3ab1ce7c" -version = "0.9.4" +version = "0.9.6" [[LLVM]] deps = ["CEnum", "LLVMExtra_jll", "Libdl", "Printf", "Unicode"] -git-tree-sha1 = "5007c1421563108110bbd57f63d8ad4565808818" +git-tree-sha1 = "7d5788011dd273788146d40eb5b1fbdc199d0296" uuid = "929cbde3-209d-540e-8aea-75f648917ca0" -version = "5.2.0" +version = "6.0.1" [[LLVMExtra_jll]] deps = ["Artifacts", "JLLWrappers", "LazyArtifacts", "Libdl", "TOML"] @@ -319,9 +319,9 @@ version = "0.2.1" [[UnsafeAtomicsLLVM]] deps = ["LLVM", "UnsafeAtomics"] -git-tree-sha1 = "ea37e6066bf194ab78f4e747f5245261f17a7175" +git-tree-sha1 = "323e3d0acf5e78a56dfae7bd8928c989b4f3083e" uuid = "d80eeb9a-aca5-4d75-85e5-170c8b632249" -version = "0.1.2" +version = "0.1.3" [[Zlib_jll]] deps = ["Libdl"] diff --git a/Project.toml b/Project.toml index 2a16d9e8..9fbea9ad 100644 --- a/Project.toml +++ b/Project.toml @@ -31,7 +31,7 @@ ExprTools = "0.1" GPUArrays = "8.4" GPUCompiler = "0.20.1, 0.21" KernelAbstractions = "0.9.1" -LLVM = "5.0" +LLVM = "6" NEO_jll = "=22.53.25593" Preferences = "1" SPIRV_LLVM_Translator_unified_jll = "0.3" diff --git a/src/compiler/compilation.jl b/src/compiler/compilation.jl index 653b5658..627dc8bb 100644 --- a/src/compiler/compilation.jl +++ b/src/compiler/compilation.jl @@ -23,17 +23,16 @@ function GPUCompiler.finish_module!(job::oneAPICompilerJob, mod::LLVM.Module) invoke(GPUCompiler.finish_module!, Tuple{CompilerJob{SPIRVCompilerTarget}, typeof(mod)}, job, mod) - ctx = LLVM.context(mod) # OpenCL 2.0 push!(metadata(mod)["opencl.ocl.version"], - MDNode([ConstantInt(Int32(2); ctx), - ConstantInt(Int32(0); ctx)]; ctx)) + MDNode([ConstantInt(Int32(2)), + ConstantInt(Int32(0))])) # SPIR-V 1.5 push!(metadata(mod)["opencl.spirv.version"], - MDNode([ConstantInt(Int32(1); ctx), - ConstantInt(Int32(5); ctx)]; ctx)) + MDNode([ConstantInt(Int32(1)), + ConstantInt(Int32(5))])) end @@ -78,12 +77,9 @@ end # compile to executable machine code function compile(@nospecialize(job::CompilerJob)) # TODO: on 1.9, this actually creates a context. cache those. - JuliaContext() do ctx - compile(job, ctx) + asm, meta = JuliaContext() do ctx + GPUCompiler.compile(:obj, job) end -end -function compile(@nospecialize(job::CompilerJob), ctx) - asm, meta = GPUCompiler.compile(:obj, job; ctx) (image=asm, entry=LLVM.name(meta.entry)) end diff --git a/src/device/opencl/memory.jl b/src/device/opencl/memory.jl index 1df8644f..a07a5107 100644 --- a/src/device/opencl/memory.jl +++ b/src/device/opencl/memory.jl @@ -21,8 +21,8 @@ end # get a pointer to local memory, with known (static) or zero length (dynamic) @generated function emit_localmemory(::Type{T}, ::Val{len}=Val(0)) where {T,len} Context() do ctx - eltyp = convert(LLVMType, T; ctx) - T_ptr = convert(LLVMType, LLVMPtr{T,AS.Local}; ctx) + eltyp = convert(LLVMType, T) + T_ptr = convert(LLVMType, LLVMPtr{T,AS.Local}) # create a function llvm_f, _ = create_function(T_ptr) @@ -39,11 +39,11 @@ end alignment!(gv, Base.datatype_alignment(T)) # generate IR - IRBuilder(ctx) do builder - entry = BasicBlock(llvm_f, "entry"; ctx) + IRBuilder() do builder + entry = BasicBlock(llvm_f, "entry") position!(builder, entry) - ptr = gep!(builder, gv_typ, gv, [ConstantInt(0; ctx), ConstantInt(0; ctx)]) + ptr = gep!(builder, gv_typ, gv, [ConstantInt(0), ConstantInt(0)]) untyped_ptr = bitcast!(builder, ptr, T_ptr) diff --git a/src/device/opencl/printf.jl b/src/device/opencl/printf.jl index da461a7d..726ef6fe 100644 --- a/src/device/opencl/printf.jl +++ b/src/device/opencl/printf.jl @@ -29,18 +29,18 @@ end arg_types = [argspec...] Context() do ctx - T_void = LLVM.VoidType(ctx) - T_int32 = LLVM.Int32Type(ctx) - T_pint8 = LLVM.PointerType(LLVM.Int8Type(ctx)) + T_void = LLVM.VoidType() + T_int32 = LLVM.Int32Type() + T_pint8 = LLVM.PointerType(LLVM.Int8Type()) # create functions - param_types = LLVMType[convert(LLVMType, typ; ctx) for typ in arg_types] + param_types = LLVMType[convert(LLVMType, typ) for typ in arg_types] llvm_f, _ = create_function(T_int32, param_types) mod = LLVM.parent(llvm_f) # generate IR - IRBuilder(ctx) do builder - entry = BasicBlock(llvm_f, "entry"; ctx) + IRBuilder() do builder + entry = BasicBlock(llvm_f, "entry") position!(builder, entry) str = globalstring_ptr!(builder, String(fmt)) @@ -48,7 +48,7 @@ end # invoke printf and return printf_typ = LLVM.FunctionType(T_int32, [T_pint8]; vararg=true) printf = LLVM.Function(mod, "printf", printf_typ) - push!(function_attributes(printf), EnumAttribute("nobuiltin"; ctx)) + push!(function_attributes(printf), EnumAttribute("nobuiltin")) chars = call!(builder, printf_typ, printf, [str, parameters(llvm_f)...]) ret!(builder, chars)