This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from NVIDIA/bugfix/nv_target_c98
Create macro fallback support for `<nv/target>` in C++03 and C
- Loading branch information
Showing
6 changed files
with
152 additions
and
42 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of libcu++, the C++ Standard Library for your entire system, | ||
// under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: pgi, nvc++ | ||
|
||
#include <nv/target> | ||
|
||
#if !defined(__CUDACC_RTC__) | ||
#include <assert.h> | ||
#include <stdio.h> | ||
#endif | ||
|
||
#ifdef __CUDACC__ | ||
# define HD_ANNO __host__ __device__ | ||
#else | ||
# define HD_ANNO | ||
#endif | ||
|
||
template <typename T> | ||
HD_ANNO bool unused(T) {return true;} | ||
|
||
// Assert macro interferes with preprocessing, wrap it in a function | ||
HD_ANNO inline void check_v(bool result) { | ||
assert(result); | ||
} | ||
|
||
HD_ANNO void test() { | ||
# if defined(__CUDA_ARCH__) | ||
int arch_val = __CUDA_ARCH__; | ||
# else | ||
int arch_val = 0; | ||
# endif | ||
|
||
unused(arch_val); | ||
|
||
NV_IF_TARGET( | ||
NV_IS_HOST, | ||
check_v(arch_val == 0); | ||
) | ||
|
||
NV_IF_TARGET( | ||
NV_IS_DEVICE, | ||
check_v(arch_val == __CUDA_ARCH__); | ||
) | ||
|
||
NV_IF_ELSE_TARGET( | ||
NV_IS_HOST, | ||
check_v(arch_val == 0);, | ||
check_v(arch_val == __CUDA_ARCH__); | ||
) | ||
} | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
test(); | ||
return 0; | ||
} |
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
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
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
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