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
break;
// Handle all cl_ulong and aliased types
case DeviceInfo::Type:
case DeviceInfo::MaxMemAllocSize:
case DeviceInfo::SingleFpConfig:
case DeviceInfo::DoubleFpConfig:
......@@ -193,6 +192,10 @@ cl_int Device::getInfo(DeviceInfo name, size_t valueSize, void *value, size_t *v
break;
// Handle all cached values
case DeviceInfo::Type:
copyValue = &mInfo.mType;
copySize = sizeof(mInfo.mType);
break;
case DeviceInfo::MaxWorkItemDimensions:
valUInt = static_cast<cl_uint>(mInfo.mMaxWorkItemSizes.size());
copyValue = &valUInt;
......@@ -347,9 +350,10 @@ cl_int Device::createSubDevices(const cl_device_partition_property *properties,
DevicePtr Device::CreateDevice(Platform &platform,
DeviceRefPtr &&parent,
cl_device_type type,
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{};
}
......@@ -361,12 +365,15 @@ bool Device::IsValid(const _cl_device_id *device)
}) != 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()),
mPlatform(platform),
mParent(std::move(parent)),
mImpl(createImplFunc(*this)),
mInfo(mImpl->createInfo())
mInfo(mImpl->createInfo(type))
{}
void Device::destroySubDevice(Device *device)
......
......@@ -49,13 +49,17 @@ class Device final : public _cl_device_id, public Object
static DevicePtr CreateDevice(Platform &platform,
DeviceRefPtr &&parent,
cl_device_type type,
const CreateImplFunc &createImplFunc);
static bool IsValid(const _cl_device_id *device);
static bool IsValidType(cl_device_type type);
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);
......
......@@ -150,9 +150,7 @@ cl_int Platform::getDeviceIDs(cl_device_type deviceType,
cl_uint found = 0u;
for (const DevicePtr &device : mDevices)
{
cl_device_type type = 0u;
if (device->getInfoULong(DeviceInfo::Type, &type) == CL_SUCCESS &&
IsDeviceTypeMatch(deviceType, type))
if (IsDeviceTypeMatch(deviceType, device->getInfo().mType))
{
if (devices != nullptr && found < numEntries)
{
......
......@@ -14,6 +14,8 @@ namespace rx
CLDeviceImpl::Info::Info() = default;
CLDeviceImpl::Info::Info(cl_device_type type) : mType(type) {}
CLDeviceImpl::Info::~Info() = default;
CLDeviceImpl::Info::Info(Info &&) = default;
......
......@@ -21,6 +21,7 @@ class CLDeviceImpl : angle::NonCopyable
struct Info
{
Info();
explicit Info(cl_device_type type);
~Info();
Info(const Info &) = delete;
......@@ -29,9 +30,10 @@ class CLDeviceImpl : angle::NonCopyable
Info(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;
NameVersionVector mILsWithVersion;
NameVersionVector mBuiltInKernelsWithVersion;
......@@ -46,7 +48,7 @@ class CLDeviceImpl : angle::NonCopyable
CLDeviceImpl(const cl::Device &device);
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 getInfoULong(cl::DeviceInfo name, cl_ulong *value) const = 0;
......
......@@ -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;
if (!GetDeviceInfo(mNative, cl::DeviceInfo::Version, valString))
......@@ -165,7 +165,8 @@ cl_int CLDeviceCL::createSubDevices(cl::Device &device,
return Ptr(new CLDeviceCL(device, nativeSubDevice));
};
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())
{
subDeviceList.clear();
......
......@@ -22,7 +22,7 @@ class CLDeviceCL : public CLDeviceImpl
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 getInfoULong(cl::DeviceInfo name, cl_ulong *value) const override;
......
......@@ -313,12 +313,46 @@ cl::DevicePtrList CLPlatformCL::createDevices(cl::Platform &platform) const
if (mNative->getDispatch().clGetDeviceIDs(mNative, CL_DEVICE_TYPE_ALL, numDevices,
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) {
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())
{
devices.clear();
......@@ -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
// it is in the same directory as the executable which contains this CL back end.
std::string libPath = angle::GetExecutableDirectory();
// it is in the same directory as the module which contains this CL back end.
// TODO(http://anglebug.com/5949) Use GetModuleDirectory when it relands
std::string libPath; // = angle::GetModuleDirectory();
if (!libPath.empty() && libPath.back() != angle::GetPathSeparator())
{
libPath += angle::GetPathSeparator();
......
......@@ -16,9 +16,9 @@ CLDeviceVk::CLDeviceVk(const cl::Device &device) : CLDeviceImpl(device) {}
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;
}
......
......@@ -21,7 +21,7 @@ class CLDeviceVk : public CLDeviceImpl
explicit CLDeviceVk(const cl::Device &device);
~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 getInfoULong(cl::DeviceInfo name, cl_ulong *value) const override;
......
......@@ -58,11 +58,12 @@ CLPlatformImpl::Info CLPlatformVk::createInfo() const
cl::DevicePtrList CLPlatformVk::createDevices(cl::Platform &platform) const
{
cl_device_type type = 0u; // TODO(jplate) Fetch device type from Vulkan
cl::DevicePtrList devices;
const cl::Device::CreateImplFunc createImplFunc = [](const cl::Device &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())
{
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