From 4cf214b94929e27a835fb65cf706bb2caf0fcbf9 Mon Sep 17 00:00:00 2001 From: Denis Bakhvalov Date: Wed, 20 Jan 2021 15:27:20 -0800 Subject: [PATCH 1/3] [SYCL] Added a new device binary property for ESIMD images --- llvm/include/llvm/Support/PropertySetIO.h | 1 + llvm/lib/Support/PropertySetIO.cpp | 1 + sycl/include/CL/sycl/detail/pi.h | 2 ++ sycl/include/CL/sycl/detail/pi.hpp | 2 ++ sycl/source/detail/pi.cpp | 1 + 5 files changed, 7 insertions(+) diff --git a/llvm/include/llvm/Support/PropertySetIO.h b/llvm/include/llvm/Support/PropertySetIO.h index d88a7e0261bf9..89978f7e140ff 100644 --- a/llvm/include/llvm/Support/PropertySetIO.h +++ b/llvm/include/llvm/Support/PropertySetIO.h @@ -187,6 +187,7 @@ class PropertySetRegistry { "SYCL/composite specialization constants"; static constexpr char SYCL_DEVICELIB_REQ_MASK[] = "SYCL/devicelib req mask"; static constexpr char SYCL_KERNEL_PARAM_OPT_INFO[] = "SYCL/kernel param opt"; + static constexpr char SYCL_IS_ESIMD_IMAGE[] = "SYCL/is ESIMD image"; // Function for bulk addition of an entire property set under given category // (property set name). diff --git a/llvm/lib/Support/PropertySetIO.cpp b/llvm/lib/Support/PropertySetIO.cpp index a47cf4fea8d25..4742ccda7a135 100644 --- a/llvm/lib/Support/PropertySetIO.cpp +++ b/llvm/lib/Support/PropertySetIO.cpp @@ -197,6 +197,7 @@ constexpr char PropertySetRegistry::SYCL_SPECIALIZATION_CONSTANTS[]; constexpr char PropertySetRegistry::SYCL_DEVICELIB_REQ_MASK[]; constexpr char PropertySetRegistry::SYCL_KERNEL_PARAM_OPT_INFO[]; constexpr char PropertySetRegistry::SYCL_COMPOSITE_SPECIALIZATION_CONSTANTS[]; +constexpr char PropertySetRegistry::SYCL_IS_ESIMD_IMAGE[]; } // namespace util } // namespace llvm diff --git a/sycl/include/CL/sycl/detail/pi.h b/sycl/include/CL/sycl/detail/pi.h index 693f15153340a..b92ca77a33ba7 100644 --- a/sycl/include/CL/sycl/detail/pi.h +++ b/sycl/include/CL/sycl/detail/pi.h @@ -670,6 +670,8 @@ static const uint8_t PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL = 4; #define __SYCL_PI_PROPERTY_SET_DEVICELIB_REQ_MASK "SYCL/devicelib req mask" /// PropertySetRegistry::SYCL_KERNEL_PARAM_OPT_INFO defined in PropertySetIO.h #define __SYCL_PI_PROPERTY_SET_KERNEL_PARAM_OPT_INFO "SYCL/kernel param opt" +/// PropertySetRegistry::SYCL_IS_ESIMD_IMAGE defined in PropertySetIO.h +#define __SYCL_PI_PROPERTY_SET_SYCL_IS_ESIMD_IMAGE "SYCL/is ESIMD image" /// This struct is a record of the device binary information. If the Kind field /// denotes a portable binary type (SPIR-V or LLVM IR), the DeviceTargetSpec diff --git a/sycl/include/CL/sycl/detail/pi.hpp b/sycl/include/CL/sycl/detail/pi.hpp index 661fffe971e7d..4d2a12c8b62f1 100644 --- a/sycl/include/CL/sycl/detail/pi.hpp +++ b/sycl/include/CL/sycl/detail/pi.hpp @@ -320,6 +320,7 @@ class DeviceBinaryImage { const PropertyRange &getKernelParamOptInfo() const { return KernelParamOptInfo; } + const PropertyRange &getSyclIsEsimdImage() const { return SyclIsEsimdImage; } virtual ~DeviceBinaryImage() {} protected: @@ -332,6 +333,7 @@ class DeviceBinaryImage { DeviceBinaryImage::PropertyRange CompositeSpecConstIDMap; DeviceBinaryImage::PropertyRange DeviceLibReqMask; DeviceBinaryImage::PropertyRange KernelParamOptInfo; + DeviceBinaryImage::PropertyRange SyclIsEsimdImage; }; /// Tries to determine the device binary image foramat. Returns diff --git a/sycl/source/detail/pi.cpp b/sycl/source/detail/pi.cpp index be58c43e42881..fbf0b296a44c3 100644 --- a/sycl/source/detail/pi.cpp +++ b/sycl/source/detail/pi.cpp @@ -603,6 +603,7 @@ void DeviceBinaryImage::init(pi_device_binary Bin) { __SYCL_PI_PROPERTY_SET_COMPOSITE_SPEC_CONST_MAP); DeviceLibReqMask.init(Bin, __SYCL_PI_PROPERTY_SET_DEVICELIB_REQ_MASK); KernelParamOptInfo.init(Bin, __SYCL_PI_PROPERTY_SET_KERNEL_PARAM_OPT_INFO); + SyclIsEsimdImage.init(Bin, __SYCL_PI_PROPERTY_SET_SYCL_IS_ESIMD_IMAGE); } } // namespace pi From d0939fca0938464f014feebbe87c84628db7cc22 Mon Sep 17 00:00:00 2001 From: Denis Bakhvalov Date: Wed, 27 Jan 2021 10:04:16 -0800 Subject: [PATCH 2/3] Fixed Vlad's comment --- sycl/include/CL/sycl/detail/pi.hpp | 5 +++-- sycl/source/detail/pi.cpp | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/sycl/include/CL/sycl/detail/pi.hpp b/sycl/include/CL/sycl/detail/pi.hpp index 4d2a12c8b62f1..c70b16be5923a 100644 --- a/sycl/include/CL/sycl/detail/pi.hpp +++ b/sycl/include/CL/sycl/detail/pi.hpp @@ -290,6 +290,9 @@ class DeviceBinaryImage { return Format; } + /// Returns the value of a single property + bool isBoolPropertyTrue(const char *PropName) const; + /// Gets the iterator range over scalar specialization constants in this /// binary image. For each property pointed to by an iterator within the /// range, the name of the property is the specialization constant symbolic ID @@ -320,7 +323,6 @@ class DeviceBinaryImage { const PropertyRange &getKernelParamOptInfo() const { return KernelParamOptInfo; } - const PropertyRange &getSyclIsEsimdImage() const { return SyclIsEsimdImage; } virtual ~DeviceBinaryImage() {} protected: @@ -333,7 +335,6 @@ class DeviceBinaryImage { DeviceBinaryImage::PropertyRange CompositeSpecConstIDMap; DeviceBinaryImage::PropertyRange DeviceLibReqMask; DeviceBinaryImage::PropertyRange KernelParamOptInfo; - DeviceBinaryImage::PropertyRange SyclIsEsimdImage; }; /// Tries to determine the device binary image foramat. Returns diff --git a/sycl/source/detail/pi.cpp b/sycl/source/detail/pi.cpp index fbf0b296a44c3..8b595d6e4910c 100644 --- a/sycl/source/detail/pi.cpp +++ b/sycl/source/detail/pi.cpp @@ -565,6 +565,13 @@ void DeviceBinaryImage::PropertyRange::init(pi_device_binary Bin, End = Begin ? PS->PropertiesEnd : nullptr; } +bool DeviceBinaryImage::isBoolPropertyTrue(const char *PropName) const { + DeviceBinaryImage::PropertyRange BoolProp; + BoolProp.init(Bin, PropName); + return BoolProp.isAvailable() && + pi::DeviceBinaryProperty(*(BoolProp.begin())).asUint32(); +} + RT::PiDeviceBinaryType getBinaryImageFormat(const unsigned char *ImgData, size_t ImgSize) { struct { @@ -603,7 +610,6 @@ void DeviceBinaryImage::init(pi_device_binary Bin) { __SYCL_PI_PROPERTY_SET_COMPOSITE_SPEC_CONST_MAP); DeviceLibReqMask.init(Bin, __SYCL_PI_PROPERTY_SET_DEVICELIB_REQ_MASK); KernelParamOptInfo.init(Bin, __SYCL_PI_PROPERTY_SET_KERNEL_PARAM_OPT_INFO); - SyclIsEsimdImage.init(Bin, __SYCL_PI_PROPERTY_SET_SYCL_IS_ESIMD_IMAGE); } } // namespace pi From f8dfd0084abb385d922a8fbf59b7cfe5b6e49f9a Mon Sep 17 00:00:00 2001 From: Denis Bakhvalov Date: Fri, 29 Jan 2021 17:28:52 -0800 Subject: [PATCH 3/3] Renamed category and introduced an API to retrieve properties from it --- llvm/include/llvm/Support/PropertySetIO.h | 2 +- llvm/lib/Support/PropertySetIO.cpp | 2 +- sycl/include/CL/sycl/detail/pi.h | 4 ++-- sycl/include/CL/sycl/detail/pi.hpp | 4 ++-- sycl/source/detail/pi.cpp | 17 +++++++++++++---- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/llvm/include/llvm/Support/PropertySetIO.h b/llvm/include/llvm/Support/PropertySetIO.h index 89978f7e140ff..e571a3679c1f7 100644 --- a/llvm/include/llvm/Support/PropertySetIO.h +++ b/llvm/include/llvm/Support/PropertySetIO.h @@ -187,7 +187,7 @@ class PropertySetRegistry { "SYCL/composite specialization constants"; static constexpr char SYCL_DEVICELIB_REQ_MASK[] = "SYCL/devicelib req mask"; static constexpr char SYCL_KERNEL_PARAM_OPT_INFO[] = "SYCL/kernel param opt"; - static constexpr char SYCL_IS_ESIMD_IMAGE[] = "SYCL/is ESIMD image"; + static constexpr char SYCL_MISC_PROP[] = "SYCL/misc properties"; // Function for bulk addition of an entire property set under given category // (property set name). diff --git a/llvm/lib/Support/PropertySetIO.cpp b/llvm/lib/Support/PropertySetIO.cpp index 4742ccda7a135..f583c91088762 100644 --- a/llvm/lib/Support/PropertySetIO.cpp +++ b/llvm/lib/Support/PropertySetIO.cpp @@ -197,7 +197,7 @@ constexpr char PropertySetRegistry::SYCL_SPECIALIZATION_CONSTANTS[]; constexpr char PropertySetRegistry::SYCL_DEVICELIB_REQ_MASK[]; constexpr char PropertySetRegistry::SYCL_KERNEL_PARAM_OPT_INFO[]; constexpr char PropertySetRegistry::SYCL_COMPOSITE_SPECIALIZATION_CONSTANTS[]; -constexpr char PropertySetRegistry::SYCL_IS_ESIMD_IMAGE[]; +constexpr char PropertySetRegistry::SYCL_MISC_PROP[]; } // namespace util } // namespace llvm diff --git a/sycl/include/CL/sycl/detail/pi.h b/sycl/include/CL/sycl/detail/pi.h index b92ca77a33ba7..da4a71c03aba0 100644 --- a/sycl/include/CL/sycl/detail/pi.h +++ b/sycl/include/CL/sycl/detail/pi.h @@ -670,8 +670,8 @@ static const uint8_t PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL = 4; #define __SYCL_PI_PROPERTY_SET_DEVICELIB_REQ_MASK "SYCL/devicelib req mask" /// PropertySetRegistry::SYCL_KERNEL_PARAM_OPT_INFO defined in PropertySetIO.h #define __SYCL_PI_PROPERTY_SET_KERNEL_PARAM_OPT_INFO "SYCL/kernel param opt" -/// PropertySetRegistry::SYCL_IS_ESIMD_IMAGE defined in PropertySetIO.h -#define __SYCL_PI_PROPERTY_SET_SYCL_IS_ESIMD_IMAGE "SYCL/is ESIMD image" +/// PropertySetRegistry::SYCL_MISC_PROP defined in PropertySetIO.h +#define __SYCL_PI_PROPERTY_SET_SYCL_MISC_PROP "SYCL/misc properties" /// This struct is a record of the device binary information. If the Kind field /// denotes a portable binary type (SPIR-V or LLVM IR), the DeviceTargetSpec diff --git a/sycl/include/CL/sycl/detail/pi.hpp b/sycl/include/CL/sycl/detail/pi.hpp index c70b16be5923a..a5998d9fbe1de 100644 --- a/sycl/include/CL/sycl/detail/pi.hpp +++ b/sycl/include/CL/sycl/detail/pi.hpp @@ -290,8 +290,8 @@ class DeviceBinaryImage { return Format; } - /// Returns the value of a single property - bool isBoolPropertyTrue(const char *PropName) const; + /// Returns a single property from SYCL_MISC_PROP category. + pi_device_binary_property getProperty(const char *PropName) const; /// Gets the iterator range over scalar specialization constants in this /// binary image. For each property pointed to by an iterator within the diff --git a/sycl/source/detail/pi.cpp b/sycl/source/detail/pi.cpp index 8b595d6e4910c..5d94cd3fe4537 100644 --- a/sycl/source/detail/pi.cpp +++ b/sycl/source/detail/pi.cpp @@ -565,11 +565,20 @@ void DeviceBinaryImage::PropertyRange::init(pi_device_binary Bin, End = Begin ? PS->PropertiesEnd : nullptr; } -bool DeviceBinaryImage::isBoolPropertyTrue(const char *PropName) const { +pi_device_binary_property +DeviceBinaryImage::getProperty(const char *PropName) const { DeviceBinaryImage::PropertyRange BoolProp; - BoolProp.init(Bin, PropName); - return BoolProp.isAvailable() && - pi::DeviceBinaryProperty(*(BoolProp.begin())).asUint32(); + BoolProp.init(Bin, __SYCL_PI_PROPERTY_SET_SYCL_MISC_PROP); + if (!BoolProp.isAvailable()) + return nullptr; + auto It = std::find_if(BoolProp.begin(), BoolProp.end(), + [=](pi_device_binary_property Prop) { + return !strcmp(PropName, Prop->Name); + }); + if (It == BoolProp.end()) + return nullptr; + + return *It; } RT::PiDeviceBinaryType getBinaryImageFormat(const unsigned char *ImgData,