Page MenuHomePhabricator

[OpenMP] Wrap (v)printf in the new RT and use same handling for AMD
ClosedPublic

Authored by jdoerfert on Oct 25 2021, 7:19 PM.

Details

Summary

To support printf NVPTX and AMD targets are handled differently. The
latter performs host calls, which we don't really want in OpenMP, the
former translates printf calls to vprintf calls as the NVIDIA
runtime provides an implementation for the device of vprintf. This
patch unifies the AMD and NVPTX handling and emits for both calls to the
vprintf wrapper __llvm_omp_vprintf which we define in our new device
runtime. The main benefit of this wrapper is that we can more easily
control (and profile) the emission of printf calls in device code.

Note: Tests are coming.

Diff Detail

Unit TestsFailed

TimeTest
240 msx64 debian > Clang.OpenMP::cancel_codegen.cpp
Script: -- : 'RUN: at line 2'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/clang -cc1 -internal-isystem /var/lib/buildkite-agent/builds/llvm-project/build/lib/clang/14.0.0/include -nostdsysteminc -verify -fopenmp -fopenmp-version=45 -triple x86_64-apple-darwin13.4.0 -emit-llvm -o - /var/lib/buildkite-agent/builds/llvm-project/clang/test/OpenMP/cancel_codegen.cpp | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck --allow-unused-prefixes /var/lib/buildkite-agent/builds/llvm-project/clang/test/OpenMP/cancel_codegen.cpp --check-prefix=CHECK1
240 msx64 debian > Clang.OpenMP::cancellation_point_codegen.cpp
Script: -- : 'RUN: at line 2'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/clang -cc1 -internal-isystem /var/lib/buildkite-agent/builds/llvm-project/build/lib/clang/14.0.0/include -nostdsysteminc -verify -fopenmp -triple x86_64-apple-darwin13.4.0 -emit-llvm -o - /var/lib/buildkite-agent/builds/llvm-project/clang/test/OpenMP/cancellation_point_codegen.cpp | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck --allow-unused-prefixes /var/lib/buildkite-agent/builds/llvm-project/clang/test/OpenMP/cancellation_point_codegen.cpp --check-prefix=CHECK1
150 msx64 debian > Clang.OpenMP::debug-info-openmp-array.cpp
Script: -- : 'RUN: at line 2'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/clang -cc1 -internal-isystem /var/lib/buildkite-agent/builds/llvm-project/build/lib/clang/14.0.0/include -nostdsysteminc -triple x86_64-unknown-linux -fopenmp -x c++ /var/lib/buildkite-agent/builds/llvm-project/clang/test/OpenMP/debug-info-openmp-array.cpp -verify -debug-info-kind=limited -emit-llvm -o - | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck --allow-unused-prefixes /var/lib/buildkite-agent/builds/llvm-project/clang/test/OpenMP/debug-info-openmp-array.cpp --check-prefix=CHECK1
930 msx64 debian > Clang.OpenMP::declare_mapper_codegen.cpp
Script: -- : 'RUN: at line 8'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/clang -cc1 -internal-isystem /var/lib/buildkite-agent/builds/llvm-project/build/lib/clang/14.0.0/include -nostdsysteminc -DCK0 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm -femit-all-decls -disable-llvm-passes /var/lib/buildkite-agent/builds/llvm-project/clang/test/OpenMP/declare_mapper_codegen.cpp -o - | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck --allow-unused-prefixes --check-prefix CK0 --check-prefix CK0-64 /var/lib/buildkite-agent/builds/llvm-project/clang/test/OpenMP/declare_mapper_codegen.cpp
130 msx64 debian > Clang.OpenMP::declare_reduction_codegen.cpp
Script: -- : 'RUN: at line 1'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/clang -cc1 -internal-isystem /var/lib/buildkite-agent/builds/llvm-project/build/lib/clang/14.0.0/include -nostdsysteminc -verify -fopenmp -x c++ -emit-llvm /var/lib/buildkite-agent/builds/llvm-project/clang/test/OpenMP/declare_reduction_codegen.cpp -triple x86_64-linux -fexceptions -fcxx-exceptions -o - -femit-all-decls -disable-llvm-passes | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck --allow-unused-prefixes /var/lib/buildkite-agent/builds/llvm-project/clang/test/OpenMP/declare_reduction_codegen.cpp
View Full Test Results (170 Failed)

Event Timeline

jdoerfert created this revision.Oct 25 2021, 7:19 PM
jdoerfert requested review of this revision.Oct 25 2021, 7:19 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 25 2021, 7:19 PM
jdoerfert updated this revision to Diff 382171.Oct 25 2021, 8:23 PM

Actually use the new wrapper for OpenMP offload targeting AMD (and the new RT)

That's an interesting approach.

Do you happen to know where I can find details of the data format behind that void*? Have been meaning to look at writing printf for amdgpu as host side decoding of that buffer. If the compiler knows how long it is, that would be a useful third argument.

jdoerfert added inline comments.Oct 26 2021, 6:33 AM
clang/lib/CodeGen/CGGPUBuiltin.cpp
128

That's an interesting approach.

Do you happen to know where I can find details of the data format behind that void*? Have been meaning to look at writing printf for amdgpu as host side decoding of that buffer. If the compiler knows how long it is, that would be a useful third argument.

We actually do know. Above we allocate and fill the buffer. For the OpenMP wrapper you could easily add a third argument later in order to facilitate an OpenMP runtime printf impl. I would even like it to be target agnostic (e.g., replace the default CUDA route on request). That said, we should tackle that separately, wdyt?

JonChesterfield added a comment.EditedOct 26 2021, 7:04 AM

Nice! Yep, can add a size argument later. Will want it to control copying the payload over to the host. Or we could allocate a buffer that the corresponding runtime can handle directly (pinned/fine grain) and skip that copy

JonChesterfield accepted this revision.Oct 26 2021, 12:12 PM
This revision is now accepted and ready to land.Oct 26 2021, 12:12 PM

This doesn't apply against main, diff relative to something that isn't in main

-rebase on main

jdoerfert closed this revision.Nov 8 2021, 10:54 AM

Committed as part of D112680.