This is an archive of the discontinued LLVM Phabricator instance.

[HIP] add -fhip-kernel-arg-name
ClosedPublic

Authored by yaxunl on Jun 16 2022, 7:26 PM.

Details

Summary

Add option -fhip-kernel-arg-name to emit kernel argument
name metadata, which is needed for certain HIP applications.

Diff Detail

Event Timeline

yaxunl created this revision.Jun 16 2022, 7:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2022, 7:26 PM
yaxunl requested review of this revision.Jun 16 2022, 7:26 PM
tra added inline comments.Jun 22 2022, 11:30 AM
clang/lib/CodeGen/CodeGenModule.cpp
1845–1846

Should we consolidate both options into -fkernel-arg-info and make -cl-kernel-arg-info an alias to it?

1845–1846

Also, this check is odd. For some reason only *arg name* metadata is set conditionally, but for whatever reason OpenCL sets other arg metadata unconditionally.

Now I'm really curious what's so special about "kernel_arg_name" vs the other arg metadata.

yaxunl marked 2 inline comments as done.Jun 22 2022, 12:06 PM
yaxunl added inline comments.
clang/lib/CodeGen/CodeGenModule.cpp
1845–1846

Should we consolidate both options into -fkernel-arg-info and make -cl-kernel-arg-info an alias to it?

-cl-kernel-arg-info is an OpenCL option defined in OpenCL spec, therefore is made OpenCL only option. It would be confusing to allow it with other languages.

1845–1846

Also, this check is odd. For some reason only *arg name* metadata is set conditionally, but for whatever reason OpenCL sets other arg metadata unconditionally.

Now I'm really curious what's so special about "kernel_arg_name" vs the other arg metadata.

The other metadata are mandatory because they are necessary for OpenCL runtime to set kernel argument.

The kernel argument name is emitted only with -cl-kernel-arg-info since it is only used to support clGetKernelArgInfo which requires -cl-kernel-arg-info to work.

tra added inline comments.Jun 22 2022, 2:25 PM
clang/lib/CodeGen/CodeGenModule.cpp
1845–1846

It would be confusing to allow it with other languages.

On the other hand having two options that control exactly the same functionality also looks odd to me.

The way I see it is that an entity may have more than one name. OpenCL standard requires that that particular functionality must be enabled via -cl-kernel-arg-info and I'm not proposing to change that. The OpenCL standard has no say whether that flag may have a different name in addition to the standard-required one.

This is similar to how over time we've been transitioning what used to be CUDA-only options into their generic -gpu and -offload variants, only in this case OpenCL functionality becomes useful outside of OpenCL.

yaxunl marked 3 inline comments as done.Jun 23 2022, 9:15 AM
yaxunl added inline comments.
clang/lib/CodeGen/CodeGenModule.cpp
1845–1846

It would be confusing to allow it with other languages.

On the other hand having two options that control exactly the same functionality also looks odd to me.

The way I see it is that an entity may have more than one name. OpenCL standard requires that that particular functionality must be enabled via -cl-kernel-arg-info and I'm not proposing to change that. The OpenCL standard has no say whether that flag may have a different name in addition to the standard-required one.

This is similar to how over time we've been transitioning what used to be CUDA-only options into their generic -gpu and -offload variants, only in this case OpenCL functionality becomes useful outside of OpenCL.

If we introduce a generic option -fkernel-arg-info and make -cl-kernel-arg-info alias to it, do we want to make it available to all languages or limit it to HIP and OpenCL only?

b-sumner added inline comments.Jun 23 2022, 10:02 AM
clang/lib/CodeGen/CodeGenModule.cpp
1845–1846

It would be confusing to allow it with other languages.

On the other hand having two options that control exactly the same functionality also looks odd to me.

The way I see it is that an entity may have more than one name. OpenCL standard requires that that particular functionality must be enabled via -cl-kernel-arg-info and I'm not proposing to change that. The OpenCL standard has no say whether that flag may have a different name in addition to the standard-required one.

This is similar to how over time we've been transitioning what used to be CUDA-only options into their generic -gpu and -offload variants, only in this case OpenCL functionality becomes useful outside of OpenCL.

If we introduce a generic option -fkernel-arg-info and make -cl-kernel-arg-info alias to it, do we want to make it available to all languages or limit it to HIP and OpenCL only?

I think that would be fine.

tra accepted this revision.Jun 23 2022, 10:44 AM
tra added inline comments.
clang/lib/CodeGen/CodeGenModule.cpp
1845–1846

If we introduce a generic option -fkernel-arg-info and make -cl-kernel-arg-info alias to it, do we want to make it available to all languages or limit it to HIP and OpenCL only?

ShouldParseIf appears to support expressions, so restricting it to hip + OCL may be as simple as

ShouldParseIf<!strconcat(open_cl.KeyPath, "||", hip.KeyPath)>;

I'm not sure what to do about -cl-kernel-arg-info being in Group<opencl_Group>. AFAICT, option currently may be only in one group. It's not a problem for now as only OpenCL arg needs to be in a group, but that is a point against merging the options. That makes my suggestion a wash -- a bit better here, possibly worse there.

I withdraw the suggestion.

This revision is now accepted and ready to land.Jun 23 2022, 10:44 AM
MaskRay accepted this revision.Jun 23 2022, 10:47 AM
MaskRay added inline comments.
clang/lib/Driver/ToolChains/Clang.cpp
6353

Use addOptInFlag

clang/test/Driver/hip-options.hip
120

This comment is redundant. There is only one CHECK line and the string is clear there.

yaxunl marked 5 inline comments as done.Jun 23 2022, 8:27 PM
yaxunl added inline comments.
clang/lib/Driver/ToolChains/Clang.cpp
6353

will do when committing

clang/test/Driver/hip-options.hip
120

will remove when commiting

This revision was landed with ongoing or failed builds.Jun 24 2022, 8:16 AM
This revision was automatically updated to reflect the committed changes.
yaxunl marked 2 inline comments as done.
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2022, 8:16 AM