2015-12-12 25 views
3

我正在編寫一些特定於平臺的優化,並且我意識到可以在主機代碼中解析供應商字符串並使用-D選項將其發送給內核的事實,在沒有主機參與的情況下直接在內核中檢測供應商可能會更方便(這樣即使不訪問主機源代碼也可以優化內核,...)。在內核代碼中檢測OpenCL設備廠商

到目前爲止,我想出了以下內容:

#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 // ... 

任何補充或更正?任何人都知道英特爾的定義

回答

0

我剛剛嘗試過使用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 

注意,無論是__GPU____Fiji__在此DLL中被發現。否則,看起來像一堆有趣的選項。請注意,並非所有這些工作,其中一些可能需要前綴-