Compilation Alea GPU是否允许在编译链中保留LLVM IR代码?

Compilation Alea GPU是否允许在编译链中保留LLVM IR代码?,compilation,cuda,llvm,llvm-ir,aleagpu,Compilation,Cuda,Llvm,Llvm Ir,Aleagpu,Nvidia不允许访问CUDA C/C++编写的GPU内核编译流中生成的LLVM IR。我想知道如果我使用Alea GPU,这是否可能?换句话说,Alea GPU编译过程是否允许保留生成的优化/未优化LLVM IR代码?是的,您是对的,Nvidia不向您显示LLVM IR,您只能获取PTX代码。虽然Alea GPU允许您通过多种方式访问LLVM IR: 方法1 使用将GPU模块编码为模板,然后将模板编译为LLVM IR模块,然后将LLVM IRModule(可选)与其他IR模块链接到PTX模块。

Nvidia不允许访问CUDA C/C++编写的GPU内核编译流中生成的LLVM IR。我想知道如果我使用Alea GPU,这是否可能?换句话说,Alea GPU编译过程是否允许保留生成的优化/未优化LLVM IR代码?

是的,您是对的,Nvidia不向您显示LLVM IR,您只能获取PTX代码。虽然Alea GPU允许您通过多种方式访问LLVM IR:

方法1 使用将GPU模块编码为模板,然后将模板编译为LLVM IR模块,然后将LLVM IRModule(可选)与其他IR模块链接到PTX模块。最后,将PTX模块加载到GPU工作进程中。获取LLVM IRModule时,可以调用其方法
Dump()
,将IR代码打印到控制台。或者,您可以将位代码设置为
字节[]

我建议您在此处阅读更多详细信息:

  • F#应该是这样的:

    let template = cuda {
        // define your kernel functions or other gpu moudle stuff
        let! kernel = <@ fun .... @> |> Compiler.DefineKernel
    
        // return an entry pointer for this module, something like the 
        // main() function for a C program
        return Entry(fun program ->
            let worker = program.Worker
            let kernel = program.Apply kernel
            let main() = ....
            main ) }
    
    let irModule = Compiler.Compile(template).IRModule
    irModule.Dump() // dump the IR code
    
    let ptxModule = Compiler.Link(irModule).PTXModule
    ptxModule.Dump()
    
    use program = worker.LoadProgram(ptxModule)
    program.Run(...)
    
    使用LLVM代码扩展GPU功能 最后,还有一种未记录的方法,可以让您直接操作LLVM IR代码来构造函数。它是由实现一些IR构建接口的属性完成的。下面是一个简单的示例,它接受参数并打印(在编译时),然后返回:

    [<AttributeUsage(AttributeTargets.Method, AllowMultiple = false)>]
    type IdentityAttribute() =
        inherit Attribute()
    
        interface ICustomCallBuilder with
            member this.Build(ctx, irObject, info, irParams) =
                match irObject, irParams with
                | None, irParam :: [] ->
                    // the irParam is of type IRValue, which you
                    // can get the LLVM native handle, by irParam.LLVM
                    // Also, you can get the type by irParam.Type, which
                    // is of type IRType, again, you can get LLVMTypeRef
                    // handle by irParam.Type.LLVM
                    // You can optionally construct LLVM instructions here.
                    printfn "irParam: %A" irParam
                    Some irParam
                | _ -> None
    
    [<Identity>]
    let identity(x:'T) : 'T = failwith "this is device function, better not call it from host"
    
    []
    类型IdentityAttribute()=
    继承属性()
    ICustomCallBuilder与的接口
    成员this.Build(ctx、irObject、info、irParams)=
    将irObject、irParams与
    |无,irParam::[]->
    //irParam的类型为IRValue,您可以
    //可以通过irParam.LLVM获取LLVM本机句柄
    //此外,您还可以通过irParam.type获取类型,其中
    //是IRType类型,同样,您可以获取LLVMTypeRef
    //由irParam.Type.LLVM处理
    //您可以选择在此处构造LLVM指令。
    printfn“irParam:%A”irParam
    一些Irpram
    |无
    []
    let identity(x:'T):'T=failwith“这是设备功能,最好不要从主机调用它”
    
    是的,您是对的,Nvidia不会向您显示LLVM IR,您只能获取PTX代码。虽然Alea GPU允许您通过多种方式访问LLVM IR:

    方法1 使用将GPU模块编码为模板,然后将模板编译为LLVM IR模块,然后将LLVM IRModule(可选)与其他IR模块链接到PTX模块。最后,将PTX模块加载到GPU工作进程中。获取LLVM IRModule时,可以调用其方法
    Dump()
    ,将IR代码打印到控制台。或者,您可以将位代码设置为
    字节[]

    我建议您在此处阅读更多详细信息:

  • F#应该是这样的:

    let template = cuda {
        // define your kernel functions or other gpu moudle stuff
        let! kernel = <@ fun .... @> |> Compiler.DefineKernel
    
        // return an entry pointer for this module, something like the 
        // main() function for a C program
        return Entry(fun program ->
            let worker = program.Worker
            let kernel = program.Apply kernel
            let main() = ....
            main ) }
    
    let irModule = Compiler.Compile(template).IRModule
    irModule.Dump() // dump the IR code
    
    let ptxModule = Compiler.Link(irModule).PTXModule
    ptxModule.Dump()
    
    use program = worker.LoadProgram(ptxModule)
    program.Run(...)
    
    使用LLVM代码扩展GPU功能 最后,还有一种未记录的方法,可以让您直接操作LLVM IR代码来构造函数。它是由实现一些IR构建接口的属性完成的。下面是一个简单的示例,它接受参数并打印(在编译时),然后返回:

    [<AttributeUsage(AttributeTargets.Method, AllowMultiple = false)>]
    type IdentityAttribute() =
        inherit Attribute()
    
        interface ICustomCallBuilder with
            member this.Build(ctx, irObject, info, irParams) =
                match irObject, irParams with
                | None, irParam :: [] ->
                    // the irParam is of type IRValue, which you
                    // can get the LLVM native handle, by irParam.LLVM
                    // Also, you can get the type by irParam.Type, which
                    // is of type IRType, again, you can get LLVMTypeRef
                    // handle by irParam.Type.LLVM
                    // You can optionally construct LLVM instructions here.
                    printfn "irParam: %A" irParam
                    Some irParam
                | _ -> None
    
    [<Identity>]
    let identity(x:'T) : 'T = failwith "this is device function, better not call it from host"
    
    []
    类型IdentityAttribute()=
    继承属性()
    ICustomCallBuilder与的接口
    成员this.Build(ctx、irObject、info、irParams)=
    将irObject、irParams与
    |无,irParam::[]->
    //irParam的类型为IRValue,您可以
    //可以通过irParam.LLVM获取LLVM本机句柄
    //此外,您还可以通过irParam.type获取类型,其中
    //是IRType类型,同样,您可以获取LLVMTypeRef
    //由irParam.Type.LLVM处理
    //您可以选择在此处构造LLVM指令。
    printfn“irParam:%A”irParam
    一些Irpram
    |无
    []
    let identity(x:'T):'T=failwith“这是设备功能,最好不要从主机调用它”
    
    是的,您是对的,Nvidia不会向您显示LLVM IR,您只能获取PTX代码。虽然Alea GPU允许您通过多种方式访问LLVM IR:

    方法1 使用将GPU模块编码为模板,然后将模板编译为LLVM IR模块,然后将LLVM IRModule(可选)与其他IR模块链接到PTX模块。最后,将PTX模块加载到GPU工作进程中。获取LLVM IRModule时,可以调用其方法
    Dump()
    ,将IR代码打印到控制台。或者,您可以将位代码设置为
    字节[]

    我建议您在此处阅读更多详细信息:

  • F#应该是这样的:

    let template = cuda {
        // define your kernel functions or other gpu moudle stuff
        let! kernel = <@ fun .... @> |> Compiler.DefineKernel
    
        // return an entry pointer for this module, something like the 
        // main() function for a C program
        return Entry(fun program ->
            let worker = program.Worker
            let kernel = program.Apply kernel
            let main() = ....
            main ) }
    
    let irModule = Compiler.Compile(template).IRModule
    irModule.Dump() // dump the IR code
    
    let ptxModule = Compiler.Link(irModule).PTXModule
    ptxModule.Dump()
    
    use program = worker.LoadProgram(ptxModule)
    program.Run(...)
    
    使用LLVM代码扩展GPU功能 最后,还有一种未记录的方法,可以让您直接操作LLVM IR代码来构造函数。它是由实现一些IR构建接口的属性完成的。下面是一个简单的示例,它接受参数并打印(在编译时),然后返回:

    [<AttributeUsage(AttributeTargets.Method, AllowMultiple = false)>]
    type IdentityAttribute() =
        inherit Attribute()
    
        interface ICustomCallBuilder with
            member this.Build(ctx, irObject, info, irParams) =
                match irObject, irParams with
                | None, irParam :: [] ->
                    // the irParam is of type IRValue, which you
                    // can get the LLVM native handle, by irParam.LLVM
                    // Also, you can get the type by irParam.Type, which
                    // is of type IRType, again, you can get LLVMTypeRef
                    // handle by irParam.Type.LLVM
                    // You can optionally construct LLVM instructions here.
                    printfn "irParam: %A" irParam
                    Some irParam
                | _ -> None
    
    [<Identity>]
    let identity(x:'T) : 'T = failwith "this is device function, better not call it from host"
    
    []
    类型IdentityAttribute()=
    继承属性()
    ICustomCallBuilder与的接口
    成员this.Build(ctx、irObject、info、irParams)=
    将irObject、irParams与
    |无,irParam::[]->
    //irParam的类型为IRValue,您可以
    //可以通过irParam.LLVM获取LLVM本机句柄
    //此外,您还可以通过irParam.type获取类型,其中
    //是IRType类型,同样,您可以获取LLVMTypeRef
    //由irParam.Type.LLVM处理
    //您可以选择在此处构造LLVM指令。
    printfn“irParam:%A”irParam
    一些Irpram
    |无
    []
    let identity(x:'T):'T=failwith“这是设备功能,最好不要从主机调用它”
    
    是的,您是对的,Nvidia不会向您显示LLVM IR,您只能获取PTX代码。而Alea G