This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Lowering from GPU to LLVM fails when the same kernel is called multiple times
AcceptedPublic

Authored by Alon_Lau on Mar 16 2023, 8:22 PM.

Details

Summary

See details about the Bug: https://github.com/llvm/llvm-project/issues/59503
I try to fix it, what do you think about this bugfix?
I don't have commit access.

Closes #59503.

Diff Detail

Event Timeline

Alon_Lau created this revision.Mar 16 2023, 8:22 PM
Herald added a reviewer: dcaballe. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Alon_Lau requested review of this revision.Mar 16 2023, 8:22 PM

It seems that the build environment doesn't have llvm-readelf or it's not in the PATH when testing`flang`:

Script:
--
: 'RUN: at line 5';   rm -f /var/lib/buildkite-agent/builds/llvm-project/build/tools/flang/test/Driver/Output/code-gen-rv64.f90.tmp.o
: 'RUN: at line 6';   /var/lib/buildkite-agent/builds/llvm-project/build/bin/flang-new -fc1 -triple riscv64-unknown-linux-gnu    -target-feature +d -target-feature +c -emit-obj /var/lib/buildkite-agent/builds/llvm-project/flang/test/Driver/code-gen-rv64.f90 -o /var/lib/buildkite-agent/builds/llvm-project/build/tools/flang/test/Driver/Output/code-gen-rv64.f90.tmp.o
: 'RUN: at line 8';   llvm-readelf -h /var/lib/buildkite-agent/builds/llvm-project/build/tools/flang/test/Driver/Output/code-gen-rv64.f90.tmp.o | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/flang/test/Driver/code-gen-rv64.f90
: 'RUN: at line 10';   rm -f /var/lib/buildkite-agent/builds/llvm-project/build/tools/flang/test/Driver/Output/code-gen-rv64.f90.tmp.o
: 'RUN: at line 11';   /var/lib/buildkite-agent/builds/llvm-project/build/bin/flang-new --target=riscv64-unknown-linux-gnu -c /var/lib/buildkite-agent/builds/llvm-project/flang/test/Driver/code-gen-rv64.f90 -o /var/lib/buildkite-agent/builds/llvm-project/build/tools/flang/test/Driver/Output/code-gen-rv64.f90.tmp.o
: 'RUN: at line 12';   llvm-readelf -h /var/lib/buildkite-agent/builds/llvm-project/build/tools/flang/test/Driver/Output/code-gen-rv64.f90.tmp.o | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/flang/test/Driver/code-gen-rv64.f90
--
Exit Code: 2
 
Command Output (stderr):
--
/var/lib/buildkite-agent/builds/llvm-project/build/tools/flang/test/Driver/Output/code-gen-rv64.f90.script: line 3: llvm-readelf: command not found
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/flang/test/Driver/code-gen-rv64.f90
VitalyR added a comment.EditedMar 17 2023, 2:56 AM

The llvm-readelf in flang/test/Driver/code-gen-rv64.f90 should be changed to llvm-readobj, according to this commit: https://github.com/llvm/llvm-project/commit/0b958fe41182c9040499e629e24cbdd250d73bf7.

cc @sunshaoce @DavidSpickett

ftynse requested changes to this revision.Mar 17 2023, 3:00 AM

Please add a test. The IR in the bug is a good start for the test, but can be simplified further.

This revision now requires changes to proceed.Mar 17 2023, 3:00 AM
ftynse retitled this revision from [github][MLIR] Lowering from GPU to LLVM fails when the same kernel is called multiple times #59503 to [MLIR] Lowering from GPU to LLVM fails when the same kernel is called multiple times.Mar 17 2023, 3:00 AM
ftynse edited the summary of this revision. (Show Details)
ftynse added a reviewer: herhut.
Alon_Lau updated this revision to Diff 506478.Mar 20 2023, 12:12 AM

add fir testcase

Please add a test. The IR in the bug is a good start for the test, but can be simplified further.

The IR test has been added in this patch, I think this is the simplest testcase now.

ftynse added inline comments.Mar 20 2023, 2:27 AM
mlir/test/Conversion/GPUCommon/kernel-call-multi-times.fir
2 ↗(On Diff #506478)

There is no reason why this file should be suffixed with ".fir". Please rename.

29 ↗(On Diff #506478)

Nit: Please add a newline.

Alon_Lau updated this revision to Diff 506822.Mar 20 2023, 7:37 PM
Alon_Lau updated this revision to Diff 506825.Mar 20 2023, 7:41 PM
Alon_Lau updated this revision to Diff 506826.Mar 20 2023, 7:48 PM

update fix-patch

Alon_Lau updated this revision to Diff 506858.Mar 21 2023, 12:18 AM

Please add a test. The IR in the bug is a good start for the test, but can be simplified further.

The gpu testcase is based on the pass-pipeline of cubin,the current compiler is not supported.

The gpu testcase is based on the pass-pipeline of cubin,the current compiler is not supported.

I'm sorry, I don't quite follow this. We have the -test-gpu-to-cubin pass specifically for testing the lowering without having the target-specific compiler. It should be possible to run that, followed by gpu-to-llvm lowering and drop everything else. The gpu-to-llvm lowering would create the single constant, we can actually check that the single constant was created. I don't mind the integration test, but it should be an addition to a unit test.

Alon_Lau updated this revision to Diff 507251.Mar 21 2023, 11:44 PM

update testcase by using test-gpu-to-cubin.

ftynse accepted this revision.Mar 22 2023, 2:05 AM
This revision is now accepted and ready to land.Mar 22 2023, 2:05 AM

The gpu testcase is based on the pass-pipeline of cubin,the current compiler is not supported.

I'm sorry, I don't quite follow this. We have the -test-gpu-to-cubin pass specifically for testing the lowering without having the target-specific compiler. It should be possible to run that, followed by gpu-to-llvm lowering and drop everything else. The gpu-to-llvm lowering would create the single constant, we can actually check that the single constant was created. I don't mind the integration test, but it should be an addition to a unit test.

I have upated the testcase by using '--test-gpu-to-cubin', but the other two testcases failed. I don't have the flangFeatureList.so. I can't fix the error, and analyze it.

This looks like an unrelated flang failure