Skip to content

What is the SYCL code compilation flow on RISC-V CPU? #17062

@TJU-PanYizhe

Description

@TJU-PanYizhe

I had llvm(this project) and oneapi-construction-kit installed on my RISC-V CPU hardware.

  • OCK here is to provide OpenCL implementation for RISC-V CPU.

clinfo and sycl-ls output as below:

Image

For example:

main.cpp
#include <sycl/sycl.hpp>
#include <vector>
#include <iostream>
using namespace sycl;
using namespace std;
constexpr int N = 16;
int main()
{
    cpu_selector d_selector;
    queue q(d_selector);
    vector<int> v(N);
    {
        buffer buf(v);
        q.submit([&](handler &h)
                 {
            accessor a(buf, h, write_only);
            h.parallel_for(N, [=](auto i)
                           { a[i] = i; }); })
            .wait();
    }
    for (int i = 0; i < N; i++)
        cout << v[i] << " ";
    cout << "\n";
    return 0;
}
# compile and execute command
clang++ -fsycl main.cpp -o main
./main

Output is as below:

Image

What is the exactly SYCL code compilation flow and execution process on RISC-V CPU?

  1. Code is splited into two parts, host code and device code, respectively.
  2. Host code is compiled with integration header by host compiler.
  3. Device code is compiled by device compiler and is translated into LLVM IR.
  4. llvm-spirv converts the LLVM IR of device code to SPIR-V.
  5. Device compiler then compile the SPIR-V to target binary or wrap the SPIR-V to the object file of host code.
  6. Executable binary file is generated.

During execution:

  1. If JIT is enabled, the SPIR-V needs to be compiled by device compiler. In this scenario, device compiler find OpenCL environment as mentioned. So SPIR-V is translated to OpenCL code then the rest of the compilation is done by OpenCL runtime?
  2. If AOT is enabled, the binary can run directly.
  • Host and device are the same RISC-V CPU in this scenario. Therefore host compiler and device compiler are the same?
  • How to set the mode of compilation, AOT or JIT? Is JIT enabled in default?

Please correct me if I was wrong. Thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions