Commit 10a8182c by John Plate Committed by Angle LUCI CQ

CL: Fix querying default device if non exists

Bug: angleproject:5992 Change-Id: Ie43f905fbb9cf41b0f6f88b2db27ebe9de9c37e8 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2906993 Commit-Queue: John Plate <jplate@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com>
parent 54ba6f01
...@@ -130,7 +130,6 @@ cl_int Device::getInfo(DeviceInfo name, size_t valueSize, void *value, size_t *v ...@@ -130,7 +130,6 @@ cl_int Device::getInfo(DeviceInfo name, size_t valueSize, void *value, size_t *v
break; break;
// Handle all cl_ulong and aliased types // Handle all cl_ulong and aliased types
case DeviceInfo::Type:
case DeviceInfo::MaxMemAllocSize: case DeviceInfo::MaxMemAllocSize:
case DeviceInfo::SingleFpConfig: case DeviceInfo::SingleFpConfig:
case DeviceInfo::DoubleFpConfig: case DeviceInfo::DoubleFpConfig:
...@@ -193,6 +192,10 @@ cl_int Device::getInfo(DeviceInfo name, size_t valueSize, void *value, size_t *v ...@@ -193,6 +192,10 @@ cl_int Device::getInfo(DeviceInfo name, size_t valueSize, void *value, size_t *v
break; break;
// Handle all cached values // Handle all cached values
case DeviceInfo::Type:
copyValue = &mInfo.mType;
copySize = sizeof(mInfo.mType);
break;
case DeviceInfo::MaxWorkItemDimensions: case DeviceInfo::MaxWorkItemDimensions:
valUInt = static_cast<cl_uint>(mInfo.mMaxWorkItemSizes.size()); valUInt = static_cast<cl_uint>(mInfo.mMaxWorkItemSizes.size());
copyValue = &valUInt; copyValue = &valUInt;
...@@ -347,9 +350,10 @@ cl_int Device::createSubDevices(const cl_device_partition_property *properties, ...@@ -347,9 +350,10 @@ cl_int Device::createSubDevices(const cl_device_partition_property *properties,
DevicePtr Device::CreateDevice(Platform &platform, DevicePtr Device::CreateDevice(Platform &platform,
DeviceRefPtr &&parent, DeviceRefPtr &&parent,
cl_device_type type,
const CreateImplFunc &createImplFunc) const CreateImplFunc &createImplFunc)
{ {
DevicePtr device(new Device(platform, std::move(parent), createImplFunc)); DevicePtr device(new Device(platform, std::move(parent), type, createImplFunc));
return device->mInfo.isValid() ? std::move(device) : DevicePtr{}; return device->mInfo.isValid() ? std::move(device) : DevicePtr{};
} }
...@@ -361,12 +365,15 @@ bool Device::IsValid(const _cl_device_id *device) ...@@ -361,12 +365,15 @@ bool Device::IsValid(const _cl_device_id *device)
}) != platforms.cend(); }) != platforms.cend();
} }
Device::Device(Platform &platform, DeviceRefPtr &&parent, const CreateImplFunc &createImplFunc) Device::Device(Platform &platform,
DeviceRefPtr &&parent,
cl_device_type type,
const CreateImplFunc &createImplFunc)
: _cl_device_id(platform.getDispatch()), : _cl_device_id(platform.getDispatch()),
mPlatform(platform), mPlatform(platform),
mParent(std::move(parent)), mParent(std::move(parent)),
mImpl(createImplFunc(*this)), mImpl(createImplFunc(*this)),
mInfo(mImpl->createInfo()) mInfo(mImpl->createInfo(type))
{} {}
void Device::destroySubDevice(Device *device) void Device::destroySubDevice(Device *device)
......
...@@ -49,13 +49,17 @@ class Device final : public _cl_device_id, public Object ...@@ -49,13 +49,17 @@ class Device final : public _cl_device_id, public Object
static DevicePtr CreateDevice(Platform &platform, static DevicePtr CreateDevice(Platform &platform,
DeviceRefPtr &&parent, DeviceRefPtr &&parent,
cl_device_type type,
const CreateImplFunc &createImplFunc); const CreateImplFunc &createImplFunc);
static bool IsValid(const _cl_device_id *device); static bool IsValid(const _cl_device_id *device);
static bool IsValidType(cl_device_type type); static bool IsValidType(cl_device_type type);
private: private:
Device(Platform &platform, DeviceRefPtr &&parent, const CreateImplFunc &createImplFunc); Device(Platform &platform,
DeviceRefPtr &&parent,
cl_device_type type,
const CreateImplFunc &createImplFunc);
void destroySubDevice(Device *device); void destroySubDevice(Device *device);
......
...@@ -150,9 +150,7 @@ cl_int Platform::getDeviceIDs(cl_device_type deviceType, ...@@ -150,9 +150,7 @@ cl_int Platform::getDeviceIDs(cl_device_type deviceType,
cl_uint found = 0u; cl_uint found = 0u;
for (const DevicePtr &device : mDevices) for (const DevicePtr &device : mDevices)
{ {
cl_device_type type = 0u; if (IsDeviceTypeMatch(deviceType, device->getInfo().mType))
if (device->getInfoULong(DeviceInfo::Type, &type) == CL_SUCCESS &&
IsDeviceTypeMatch(deviceType, type))
{ {
if (devices != nullptr && found < numEntries) if (devices != nullptr && found < numEntries)
{ {
......
...@@ -14,6 +14,8 @@ namespace rx ...@@ -14,6 +14,8 @@ namespace rx
CLDeviceImpl::Info::Info() = default; CLDeviceImpl::Info::Info() = default;
CLDeviceImpl::Info::Info(cl_device_type type) : mType(type) {}
CLDeviceImpl::Info::~Info() = default; CLDeviceImpl::Info::~Info() = default;
CLDeviceImpl::Info::Info(Info &&) = default; CLDeviceImpl::Info::Info(Info &&) = default;
......
...@@ -21,6 +21,7 @@ class CLDeviceImpl : angle::NonCopyable ...@@ -21,6 +21,7 @@ class CLDeviceImpl : angle::NonCopyable
struct Info struct Info
{ {
Info(); Info();
explicit Info(cl_device_type type);
~Info(); ~Info();
Info(const Info &) = delete; Info(const Info &) = delete;
...@@ -29,9 +30,10 @@ class CLDeviceImpl : angle::NonCopyable ...@@ -29,9 +30,10 @@ class CLDeviceImpl : angle::NonCopyable
Info(Info &&); Info(Info &&);
Info &operator=(Info &&); Info &operator=(Info &&);
bool isValid() const { return mVersion != 0u; } bool isValid() const { return mType != 0u; }
cl_version mVersion = 0u; cl_device_type mType = 0u;
cl_version mVersion = 0u;
std::vector<size_t> mMaxWorkItemSizes; std::vector<size_t> mMaxWorkItemSizes;
NameVersionVector mILsWithVersion; NameVersionVector mILsWithVersion;
NameVersionVector mBuiltInKernelsWithVersion; NameVersionVector mBuiltInKernelsWithVersion;
...@@ -46,7 +48,7 @@ class CLDeviceImpl : angle::NonCopyable ...@@ -46,7 +48,7 @@ class CLDeviceImpl : angle::NonCopyable
CLDeviceImpl(const cl::Device &device); CLDeviceImpl(const cl::Device &device);
virtual ~CLDeviceImpl(); virtual ~CLDeviceImpl();
virtual Info createInfo() const = 0; virtual Info createInfo(cl_device_type type) const = 0;
virtual cl_int getInfoUInt(cl::DeviceInfo name, cl_uint *value) const = 0; virtual cl_int getInfoUInt(cl::DeviceInfo name, cl_uint *value) const = 0;
virtual cl_int getInfoULong(cl::DeviceInfo name, cl_ulong *value) const = 0; virtual cl_int getInfoULong(cl::DeviceInfo name, cl_ulong *value) const = 0;
......
...@@ -52,9 +52,9 @@ CLDeviceCL::~CLDeviceCL() ...@@ -52,9 +52,9 @@ CLDeviceCL::~CLDeviceCL()
} }
} }
CLDeviceImpl::Info CLDeviceCL::createInfo() const CLDeviceImpl::Info CLDeviceCL::createInfo(cl_device_type type) const
{ {
Info info; Info info(type);
std::vector<char> valString; std::vector<char> valString;
if (!GetDeviceInfo(mNative, cl::DeviceInfo::Version, valString)) if (!GetDeviceInfo(mNative, cl::DeviceInfo::Version, valString))
...@@ -165,7 +165,8 @@ cl_int CLDeviceCL::createSubDevices(cl::Device &device, ...@@ -165,7 +165,8 @@ cl_int CLDeviceCL::createSubDevices(cl::Device &device,
return Ptr(new CLDeviceCL(device, nativeSubDevice)); return Ptr(new CLDeviceCL(device, nativeSubDevice));
}; };
subDeviceList.emplace_back(cl::Device::CreateDevice( subDeviceList.emplace_back(cl::Device::CreateDevice(
device.getPlatform(), cl::DeviceRefPtr(&device), createImplFunc)); device.getPlatform(), cl::DeviceRefPtr(&device),
(device.getInfo().mType & ~CL_DEVICE_TYPE_DEFAULT), createImplFunc));
if (!subDeviceList.back()) if (!subDeviceList.back())
{ {
subDeviceList.clear(); subDeviceList.clear();
......
...@@ -22,7 +22,7 @@ class CLDeviceCL : public CLDeviceImpl ...@@ -22,7 +22,7 @@ class CLDeviceCL : public CLDeviceImpl
cl_device_id getNative(); cl_device_id getNative();
Info createInfo() const override; Info createInfo(cl_device_type type) const override;
cl_int getInfoUInt(cl::DeviceInfo name, cl_uint *value) const override; cl_int getInfoUInt(cl::DeviceInfo name, cl_uint *value) const override;
cl_int getInfoULong(cl::DeviceInfo name, cl_ulong *value) const override; cl_int getInfoULong(cl::DeviceInfo name, cl_ulong *value) const override;
......
...@@ -313,12 +313,46 @@ cl::DevicePtrList CLPlatformCL::createDevices(cl::Platform &platform) const ...@@ -313,12 +313,46 @@ cl::DevicePtrList CLPlatformCL::createDevices(cl::Platform &platform) const
if (mNative->getDispatch().clGetDeviceIDs(mNative, CL_DEVICE_TYPE_ALL, numDevices, if (mNative->getDispatch().clGetDeviceIDs(mNative, CL_DEVICE_TYPE_ALL, numDevices,
nativeDevices.data(), nullptr) == CL_SUCCESS) nativeDevices.data(), nullptr) == CL_SUCCESS)
{ {
for (cl_device_id nativeDevice : nativeDevices) // Fetch all device types for front end initialization, and find the default device.
// If none exists declare first device as default.
std::vector<cl_device_type> types(nativeDevices.size(), 0u);
size_t defaultIndex = 0u;
for (size_t index = 0u; index < nativeDevices.size(); ++index)
{ {
if (nativeDevices[index]->getDispatch().clGetDeviceInfo(
nativeDevices[index], CL_DEVICE_TYPE, sizeof(cl_device_type), &types[index],
nullptr) == CL_SUCCESS)
{
// If default device found, select it
if ((types[index] & CL_DEVICE_TYPE_DEFAULT) != 0u)
{
defaultIndex = index;
}
}
else
{
types.clear();
nativeDevices.clear();
}
}
for (size_t index = 0u; index < nativeDevices.size(); ++index)
{
// Make sure the default bit is set in exactly one device
if (index == defaultIndex)
{
types[index] |= CL_DEVICE_TYPE_DEFAULT;
}
else
{
types[index] &= ~CL_DEVICE_TYPE_DEFAULT;
}
const cl::Device::CreateImplFunc createImplFunc = [&](const cl::Device &device) { const cl::Device::CreateImplFunc createImplFunc = [&](const cl::Device &device) {
return CLDeviceCL::Ptr(new CLDeviceCL(device, nativeDevice)); return CLDeviceCL::Ptr(new CLDeviceCL(device, nativeDevices[index]));
}; };
devices.emplace_back(cl::Device::CreateDevice(platform, nullptr, createImplFunc)); devices.emplace_back(
cl::Device::CreateDevice(platform, nullptr, types[index], createImplFunc));
if (!devices.back()) if (!devices.back())
{ {
devices.clear(); devices.clear();
...@@ -393,8 +427,9 @@ void CLPlatformCL::Initialize(const cl_icd_dispatch &dispatch, bool isIcd) ...@@ -393,8 +427,9 @@ void CLPlatformCL::Initialize(const cl_icd_dispatch &dispatch, bool isIcd)
} }
// The absolute path to ANGLE's OpenCL library is needed and it is assumed here that // The absolute path to ANGLE's OpenCL library is needed and it is assumed here that
// it is in the same directory as the executable which contains this CL back end. // it is in the same directory as the module which contains this CL back end.
std::string libPath = angle::GetExecutableDirectory(); // TODO(http://anglebug.com/5949) Use GetModuleDirectory when it relands
std::string libPath; // = angle::GetModuleDirectory();
if (!libPath.empty() && libPath.back() != angle::GetPathSeparator()) if (!libPath.empty() && libPath.back() != angle::GetPathSeparator())
{ {
libPath += angle::GetPathSeparator(); libPath += angle::GetPathSeparator();
......
...@@ -16,9 +16,9 @@ CLDeviceVk::CLDeviceVk(const cl::Device &device) : CLDeviceImpl(device) {} ...@@ -16,9 +16,9 @@ CLDeviceVk::CLDeviceVk(const cl::Device &device) : CLDeviceImpl(device) {}
CLDeviceVk::~CLDeviceVk() = default; CLDeviceVk::~CLDeviceVk() = default;
CLDeviceImpl::Info CLDeviceVk::createInfo() const CLDeviceImpl::Info CLDeviceVk::createInfo(cl_device_type type) const
{ {
CLDeviceImpl::Info info; Info info(type);
return info; return info;
} }
......
...@@ -21,7 +21,7 @@ class CLDeviceVk : public CLDeviceImpl ...@@ -21,7 +21,7 @@ class CLDeviceVk : public CLDeviceImpl
explicit CLDeviceVk(const cl::Device &device); explicit CLDeviceVk(const cl::Device &device);
~CLDeviceVk() override; ~CLDeviceVk() override;
Info createInfo() const override; Info createInfo(cl_device_type type) const override;
cl_int getInfoUInt(cl::DeviceInfo name, cl_uint *value) const override; cl_int getInfoUInt(cl::DeviceInfo name, cl_uint *value) const override;
cl_int getInfoULong(cl::DeviceInfo name, cl_ulong *value) const override; cl_int getInfoULong(cl::DeviceInfo name, cl_ulong *value) const override;
......
...@@ -58,11 +58,12 @@ CLPlatformImpl::Info CLPlatformVk::createInfo() const ...@@ -58,11 +58,12 @@ CLPlatformImpl::Info CLPlatformVk::createInfo() const
cl::DevicePtrList CLPlatformVk::createDevices(cl::Platform &platform) const cl::DevicePtrList CLPlatformVk::createDevices(cl::Platform &platform) const
{ {
cl_device_type type = 0u; // TODO(jplate) Fetch device type from Vulkan
cl::DevicePtrList devices; cl::DevicePtrList devices;
const cl::Device::CreateImplFunc createImplFunc = [](const cl::Device &device) { const cl::Device::CreateImplFunc createImplFunc = [](const cl::Device &device) {
return CLDeviceVk::Ptr(new CLDeviceVk(device)); return CLDeviceVk::Ptr(new CLDeviceVk(device));
}; };
devices.emplace_back(cl::Device::CreateDevice(platform, nullptr, createImplFunc)); devices.emplace_back(cl::Device::CreateDevice(platform, nullptr, type, createImplFunc));
if (!devices.back()) if (!devices.back())
{ {
devices.clear(); devices.clear();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment