Skip to content

Instantly share code, notes, and snippets.

@germannp
Created July 17, 2019 21:40
Show Gist options
  • Save germannp/0f154f63d92e508b45af86d81139f2b2 to your computer and use it in GitHub Desktop.
Save germannp/0f154f63d92e508b45af86d81139f2b2 to your computer and use it in GitHub Desktop.
// Won't compile for device:
template<typename T>
__device__ T add_one(T x)
{
return x + 1;
}
template<typename T>
using Function = T(T x);
template<typename T, Function<T> func = add_one<T>>
__global__ void wrapper() {
int i = 1336;
func(i);
}
int main(int argc, char const *argv[]) {
wrapper<int><<<1, 8>>>();
cudaDeviceSynchronize();
return 0;
}
// Compiles fine for host:
template<typename T>
T add_one(T x)
{
return x + 1;
}
template<typename T>
using Function = T(T x);
template<typename T, Function<T> func = add_one<T>>
void wrapper() {
int i = 1336;
func(i);
}
int main(int argc, char const *argv[]) {
wrapper<int>();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment