|
1 | | -//==---- SYCLRequiredDeviceLibs.cpp - get SYCL devicelib required Info -----==// |
| 1 | +//==----- SYCLDeviceLibReqMask.cpp - get SYCL devicelib required Info ------==// |
2 | 2 | // |
3 | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | 4 | // See https://llvm.org/LICENSE.txt for license information. |
|
14 | 14 | // SYCL runtime later. |
15 | 15 | //===----------------------------------------------------------------------===// |
16 | 16 |
|
17 | | -#include "llvm/SYCLLowerIR/SYCLRequiredDeviceLibs.h" |
18 | | -#include "llvm/ADT/SmallSet.h" |
| 17 | +#include "llvm/SYCLLowerIR/SYCLDeviceLibReqMask.h" |
19 | 18 | #include "llvm/IR/Module.h" |
20 | 19 | #include "llvm/TargetParser/Triple.h" |
21 | 20 |
|
@@ -733,73 +732,46 @@ SYCLDeviceLibFuncMap SDLMap = { |
733 | 732 | DeviceLibExt::cl_intel_devicelib_bfloat16}, |
734 | 733 | }; |
735 | 734 |
|
736 | | -} // namespace |
737 | | - |
738 | | -// One devicelib extension may correspond to multiple spv files, following |
739 | | -// map stores corresponding index values in SPVMetaList for an extension. |
740 | | -static std::unordered_map<DeviceLibExt, std::vector<size_t>> |
741 | | - DeviceLibSPVExtMap = {{DeviceLibExt::cl_intel_devicelib_assert, {0}}, |
742 | | - {DeviceLibExt::cl_intel_devicelib_math, {1}}, |
743 | | - {DeviceLibExt::cl_intel_devicelib_math_fp64, {2}}, |
744 | | - {DeviceLibExt::cl_intel_devicelib_complex, {3}}, |
745 | | - {DeviceLibExt::cl_intel_devicelib_complex_fp64, {4}}, |
746 | | - {DeviceLibExt::cl_intel_devicelib_cstring, {5}}, |
747 | | - {DeviceLibExt::cl_intel_devicelib_imf, {6}}, |
748 | | - {DeviceLibExt::cl_intel_devicelib_imf_fp64, {7}}, |
749 | | - {DeviceLibExt::cl_intel_devicelib_imf_bf16, {8}}, |
750 | | - {DeviceLibExt::cl_intel_devicelib_bfloat16, {9, 10}}}; |
| 735 | +// Each fallback device library corresponds to one bit in "require mask" which |
| 736 | +// is an unsigned int32. getDeviceLibBit checks which fallback device library |
| 737 | +// is required for FuncName and returns the corresponding bit. The corresponding |
| 738 | +// mask for each fallback device library is: |
| 739 | +// cl_intel_devicelib_assert: 0x1 |
| 740 | +// cl_intel_devicelib_math: 0x2 |
| 741 | +// cl_intel_devicelib_math_fp64: 0x4 |
| 742 | +// cl_intel_devicelib_complex: 0x8 |
| 743 | +// cl_intel_devicelib_complex_fp64: 0x10 |
| 744 | +// cl_intel_devicelib_cstring : 0x20 |
| 745 | +// cl_intel_devicelib_imf: 0x40 |
| 746 | +// cl_intel_devicelib_imf_fp64: 0x80 |
| 747 | +// cl_intel_devicelib_imf_bf16: 0x100 |
| 748 | +// cl_intel_devicelib_bfloat16: 0x200 |
| 749 | +uint32_t getDeviceLibBits(const std::string &FuncName) { |
| 750 | + auto DeviceLibFuncIter = SDLMap.find(FuncName); |
| 751 | + return ((DeviceLibFuncIter == SDLMap.end()) |
| 752 | + ? 0 |
| 753 | + : 0x1 << (static_cast<uint32_t>(DeviceLibFuncIter->second) - |
| 754 | + static_cast<uint32_t>( |
| 755 | + DeviceLibExt::cl_intel_devicelib_assert))); |
| 756 | +} |
751 | 757 |
|
752 | | -static SYCLDeviceLibSPVMeta SPVMetaList[] = { |
753 | | - {DeviceLibExt::cl_intel_devicelib_assert, "libsycl-fallback-cassert.spv", |
754 | | - DeviceLibIsNative::Ignore}, |
755 | | - {DeviceLibExt::cl_intel_devicelib_math, "libsycl-fallback-cmath.spv", |
756 | | - DeviceLibIsNative::Ignore}, |
757 | | - {DeviceLibExt::cl_intel_devicelib_math_fp64, |
758 | | - "libsycl-fallback-cmath-fp64.spv", DeviceLibIsNative::Ignore}, |
759 | | - {DeviceLibExt::cl_intel_devicelib_complex, "libsycl-fallback-complex.spv", |
760 | | - DeviceLibIsNative::Ignore}, |
761 | | - {DeviceLibExt::cl_intel_devicelib_complex_fp64, |
762 | | - "libsycl-fallback-complex-fp64.spv", DeviceLibIsNative::Ignore}, |
763 | | - {DeviceLibExt::cl_intel_devicelib_cstring, "libsycl-fallback-cstring.spv", |
764 | | - DeviceLibIsNative::Ignore}, |
765 | | - {DeviceLibExt::cl_intel_devicelib_imf, "libsycl-fallback-imf.spv", |
766 | | - DeviceLibIsNative::Ignore}, |
767 | | - {DeviceLibExt::cl_intel_devicelib_imf_fp64, "libsycl-fallback-imf-fp64.spv", |
768 | | - DeviceLibIsNative::Ignore}, |
769 | | - {DeviceLibExt::cl_intel_devicelib_imf_bf16, "libsycl-fallback-imf-bf16.spv", |
770 | | - DeviceLibIsNative::Ignore}, |
771 | | - {DeviceLibExt::cl_intel_devicelib_bfloat16, "libsycl-fallback-bfloat16.spv", |
772 | | - DeviceLibIsNative::No}, |
773 | | - {DeviceLibExt::cl_intel_devicelib_bfloat16, "libsycl-native-bfloat16.spv", |
774 | | - DeviceLibIsNative::Yes}}; |
| 758 | +} // namespace |
775 | 759 |
|
776 | | -namespace llvm { |
777 | 760 | // For each device image module, we go through all functions which meets |
778 | 761 | // 1. The function name has prefix "__devicelib_" |
779 | 762 | // 2. The function is declaration which means it doesn't have function body |
780 | 763 | // And we don't expect non-spirv functions with "__devicelib_" prefix. |
781 | | -void getRequiredSYCLDeviceLibs( |
782 | | - const Module &M, |
783 | | - llvm::SmallVector<SYCLDeviceLibSPVMeta, 16> &ReqDeviceLibs) { |
| 764 | +uint32_t llvm::getSYCLDeviceLibReqMask(const Module &M) { |
784 | 765 | // Device libraries will be enabled only for spir-v module. |
785 | 766 | if (!Triple(M.getTargetTriple()).isSPIROrSPIRV()) |
786 | | - return; |
787 | | - |
788 | | - SmallSet<DeviceLibExt, 16> DeviceLibUsed; |
| 767 | + return 0; |
| 768 | + uint32_t ReqMask = 0; |
789 | 769 | for (const Function &SF : M) { |
790 | 770 | if (SF.getName().starts_with(DEVICELIB_FUNC_PREFIX) && SF.isDeclaration()) { |
791 | 771 | assert(SF.getCallingConv() == CallingConv::SPIR_FUNC); |
792 | | - auto DeviceLibFuncIter = SDLMap.find(SF.getName().str()); |
793 | | - if (DeviceLibFuncIter == SDLMap.end()) |
794 | | - continue; |
795 | | - if (DeviceLibUsed.contains(DeviceLibFuncIter->second)) |
796 | | - continue; |
797 | | - |
798 | | - DeviceLibUsed.insert(DeviceLibFuncIter->second); |
799 | | - for (size_t idx : DeviceLibSPVExtMap[DeviceLibFuncIter->second]) { |
800 | | - ReqDeviceLibs.push_back(SPVMetaList[idx]); |
801 | | - } |
| 772 | + uint32_t DeviceLibBits = getDeviceLibBits(SF.getName().str()); |
| 773 | + ReqMask |= DeviceLibBits; |
802 | 774 | } |
803 | 775 | } |
| 776 | + return ReqMask; |
804 | 777 | } |
805 | | -} // namespace llvm |
0 commit comments