Printf hide on device side II.
MODIFY
README.md
README.md
@@ -64,6 +64,16 @@ make package
[sudo] make install
```
+### Macro options
+
+```
+# Performance improvement option. If you define THRUST_HIP_PRINTF_ENABLED before
+# thrust includes to 0, you can disable printfs on device side and improve
+# performance. The default value is 1
+#define THRUST_HIP_PRINTF_ENABLED 0
+
+```
+
### Using rocThrust In A Project
Recommended way of including rocThrust into a CMake project is by using its package

MODIFY
thrust/system/hip/detail/terminate.h
thrust/system/hip/detail/terminate.h
@@ -50,7 +50,7 @@ void THRUST_HIP_DEVICE_FUNCTION terminate()
void THRUST_HIP_FUNCTION terminate_with_message(const char* message)
{
THRUST_HIP_PRINTF("%s\n", message);
-#ifndef THRUST_HIP_PRINTF_ENABLED
+#if THRUST_HIP_PRINTF_ENABLED == 0
THRUST_UNUSED_VAR(message);
#endif
thrust::hip_rocprim::terminate();

MODIFY
thrust/system/hip/detail/util.h
thrust/system/hip/detail/util.h
#include <thrust/system/hip/error.h>
#include <thrust/system_error.h>
-// Enable if you want printf on device side
-// #define THRUST_HIP_PRINTF_ENABLED 1
+// Define the value to 0, if you want to disable printf on device side.
+#ifndef THRUST_HIP_PRINTF_ENABLED
+#define THRUST_HIP_PRINTF_ENABLED 1
+#endif
-#ifdef THRUST_HIP_PRINTF_ENABLED
+#if THRUST_HIP_PRINTF_ENABLED == 1
#define THRUST_HIP_PRINTF(text, ...) \
printf(text, ##__VA_ARGS__)
#else
@@ -146,7 +148,7 @@ static void __host__ __device__ throw_on_error(hipError_t status, char const* ms
printf("Error after %s: %s\n", msg, hipGetErrorString(status));
#else
THRUST_HIP_PRINTF("Error %d: %s \n", (int)status, msg);
- #ifndef THRUST_HIP_PRINTF_ENABLED
+ #if THRUST_HIP_PRINTF_ENABLED == 0
THRUST_UNUSED_VAR(status);
THRUST_UNUSED_VAR(msg);
#endif

Printf hide on device side II.