Created
July 17, 2019 21:40
-
-
Save germannp/0f154f63d92e508b45af86d81139f2b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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