llvm / clangir

A new (MLIR based) high-level IR for clang.
https://clangir.org
Other
307 stars 84 forks source link

[GSoC] Add OpenCL support to compile GPU kernels #689

Open seven-mile opened 2 weeks ago

seven-mile commented 2 weeks ago

This is the overview issue for the GSoC project Compile GPU kernels using ClangIR.

Participant: @seven-mile

Mentors: @jopperm @Naghasan @bcardosolopes


Goal 1: Teach CIR pointers about address space

Status: WIP

We are discussing how we rectify the design of address space that currently mimics the one in LLVM IR in the PR #682. There are two options:

There's a draft PR #692 implementing the common base of both options.

This is closely related to the alloca address space in SPIR-V target. More details see also Goal 2.

Goal 2: Add SPIR-V target to CIRGen

Status: Partially Done

Currently we are coordinating this goal with the WIP TargetLowering library (TODO: Link to another overview issue) from @sitio-couto . We shall especially depend on the progress of CallingConvAttr.

Besides, a more direct block is that the frontend's using LangAS::FirstTargetAddressSpace as the alloca address space in SPIR-V, rather than LangAS::Default like other targets. Such behavior leads to some NYIs whose implementations cannot be tested directly. More details provided in #671.

We made it incremental, that is merging a PR with getAllocaAddressSpace unimplemented. For improvement, we are to rectify the design of address space as stated in Goal 1. After finishing it, we can use the corresponding alloca address space for getAllocaAddressSpace method.

Further more, the target-specific address space map is not available during lowering to LLVM, blocking the usages of address spaces like opencl_global. The test cases for it were marked XFAIL in #692 .

Goal 3: Support OpenCL vector types

Status: Done

This is a rather independent feature, which also leaves several future works like the issues at the end of the list.

Goal 4: Emit OpenCL kernel and module metadata

Status: WIP

As pointed out in this thread, MLIR prefers structured and well-defined attributes rather than a large dictionary like LLVM Metadata. We shall design something like OpenCLKernelArgMetadataAttr.

Now OpenCLKernelMetadataAttr is completed and ready for review.

Goal 5: Support OpenCL built-ins

Status: Blocked by Goal 2