在内核代码中检测OpenCL设备供应商

5

我正在编写一些平台特定的优化,虽然我知道在宿主代码中可以解析供应商字符串并使用-D选项将其发送到内核,但直接在内核中检测供应商可能更方便,无需涉及宿主(这样即使没有访问宿主源代码也可以优化内核)。

到目前为止,我想到了以下方法:

#ifdef __NV_CL_C_VERSION
/**
 *  @def NVIDIA
 *  @brief defined when compiling on NVIDIA GPUs
 */
#define NVIDIA
#endif // __NV_CL_C_VERSION

#if defined(__WinterPark__) || defined(__BeaverCreek__) || defined(__Turks__) || \
    defined(__Caicos__) || defined(__Tahiti__) || defined(__Pitcairn__) || \
    defined(__Capeverde__) || defined(__Cayman__) || defined(__Barts__) || \
    defined(__Cypress__) || defined(__Juniper__) || defined(__Redwood__) || \
    defined(__Cedar__) || defined(__ATI_RV770__) || defined(__ATI_RV730__) || \
    defined(__ATI_RV710__) || defined(__Loveland__) || defined(__GPU__) || \
    defined(__Hawaii__)
#define AMD
/**
 *  @def AMD
 *  @brief defined when compiling on AMD GPUs
 *  @note This list was originally found at https://github.com/magnumripper/JohnTheRipper/wiki/Predefined-macros-in-OpenCL-(standard-and-proprietary) and copied shamelessly. It is most definitely incomplete and contains the troubling  __GPU__.
 *  @note AMD also defines __CPU__ when compiling for CL_DEVICE_TYPE_CPU.
 */
#endif // ...

需要添加或纠正的内容吗?有人知道Intel的定义吗?

1个回答

1
我刚刚尝试了使用1912.5驱动的AMD Fury X。以下三个测试都会打印出消息:
#ifdef cl_amd_device_attribute_query
#pragma message "here goes AMD"
#endif

#ifdef __GPU__
#pragma message "here goes AMD GPU"
#endif

#ifdef __Fiji__
#pragma message "here goes Fiji AMD"
#endif

然而请注意,cl_amd_device_attribute_query并不是一个好的AMD设备测试方法,因为AMD平台也将英特尔CPU视为设备,并为其提供相同的扩展。遗憾。
我正在查看amdocl64.dll,注意到以下内容:
-cl-std=CL2.0
#define __clang__ 1
#define __clang_major__ 3
#define __clang_minor__ 6
#define __ENDIAN_LITTLE__ 1
#define __SPIR32 1
#define __SPIR32__ 1
#define __STDC__ 1
#define __STDC_HOSTED__ 1
#define __STDC_VERSION__ 199901L
#define __STDC_UTF_16__ 1
#define __STDC_UTF_32__ 1
#define __OPENCL_C_VERSION__ 200
#define __OPENCL_VERSION__ 200
-Wf,--force_disable_spir
-fno-lib-no-inline
-fno-sc-keep-calls
-fno-enable-dump
-cl-internal-kernel
-cl-std=CL
-cl-std=CL1.2
-just-kernel=
-DFP_FAST_FMAF=1
-DFP_FAST_FMA=1
-cl-denorms-are-zero
cl-kernel-arg-info
-fno-bin-llvmir
-fno-image-support
-mfast-fmaf
-mfast-fma kernel-arg-alignment

请注意,此 dll 中均未找到 __GPU____Fiji__。否则似乎有许多有趣的选项。请注意,并非所有选项都有效,其中一些可能需要在前面加上 -

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接