Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Change DeviceCount() to use the new host/device code pattern
Browse files Browse the repository at this point in the history
The function DeviceCount was still using "#if CUB_PTX_ARCH == 0" to separate
host code and device code.  Change it to use the new pattern of
"if (CUB_IS_HOST_CODE)".
  • Loading branch information
dkolsen-pgi authored and alliepiper committed Apr 8, 2020
1 parent f7ad39d commit 8bdfee7
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions cub/util_device.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,27 @@ struct ValueCache
*/
CUB_RUNTIME_FUNCTION __forceinline__ int DeviceCount()
{
#if __cplusplus >= 201103L && (CUB_PTX_ARCH == 0) // Host code and C++11.

// C++11 guarantees that initialization of static locals is thread safe.
static ValueCache<int, DeviceCountUncached> cache;

return cache.value;

#else // Device code or host code before C++11.

return DeviceCountUncached();
int result = -1;
if (CUB_IS_HOST_CODE) {
#if CUB_INCLUDE_HOST_CODE
#if __cplusplus >= 201103L
// Host code and C++11.
// C++11 guarantees that initialization of static locals is thread safe.
static ValueCache<int, DeviceCountUncached> cache;

#endif
result = cache.value;
#else
// Host code and C++98.
result = DeviceCountUncached();
#endif
#endif
} else {
#if CUB_INCLUDE_DEVICE_CODE
// Device code.
result = DeviceCountUncached();
#endif
}
return result;
}

#if __cplusplus >= 201103L // C++11 and later.
Expand Down

0 comments on commit 8bdfee7

Please sign in to comment.