This is an archive of the discontinued LLVM Phabricator instance.

[CUDA][HIP] Enable kernel function return type deduction.
ClosedPublic

Authored by hliao on Sep 25 2019, 8:39 AM.

Details

Summary
  • Even though only void is still accepted as the deduced return type, enabling deduction/instantiation on the return type allows more consistent coding.

Diff Detail

Event Timeline

hliao created this revision.Sep 25 2019, 8:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 25 2019, 8:39 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tra accepted this revision.Sep 25 2019, 9:34 AM

Nice. I'd mention in the commit message that NVCC does not support deduced return type for kernel functions.

This revision is now accepted and ready to land.Sep 25 2019, 9:34 AM
hliao added a comment.Sep 25 2019, 9:49 AM
In D68031#1682822, @tra wrote:

Nice. I'd mention in the commit message that NVCC does not support deduced return type for kernel functions.

Just tried with NVCC from CUDA 10, except auto-based deduced type is not supported, type deduction in a template is supported, the following test code passes compilation with NVCC

#include <cuda.h>

template <typename T>
__global__ T foo() {
}

void f0() {
  foo<void><<<0, 0>>>();
#if 0
  foo<int><<<0, 0>>>();
#endif
}

template <bool Cond, typename T = void> struct enable_if { typedef T type; };
template <typename T> struct enable_if<false, T> {};

template <int N>
__global__
auto bar() -> typename enable_if<N == 1>::type {
}

template <int N>
__global__
auto bar() -> typename enable_if<N == 2>::type {
}

void f3() {
  bar<1><<<0, 0>>>();
  bar<2><<<0, 0>>>();
#if 0
  bar<3><<<0, 0>>>();
#endif
}

s/#if 0/#if 1 also shows NVCC could give the error on the correct position but the message, IMHO, is misleading compared to the one from clang.

This revision was automatically updated to reflect the committed changes.