aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGil Pitney <gil.pitney@linaro.org>2015-06-24 00:17:46 +0000
committerGil Pitney <gil.pitney@linaro.org>2015-06-24 00:17:46 +0000
commit1145df21bed854b764d974b2c9eae56364857f0a (patch)
treee5710751a572c1c95ccdc20343e0a843269d81bb
parent634950819358e754e7dfb83a91f6c1d9253ba0e8 (diff)
Sub-devices inherit the parent's kernel and program device dependent structs.
This implements an aspect of the clCreateSubDevices() API, per the v1.2 spec: "A program binary (compiled binary, library binary or executable binary) built for a parent device can be used by all its sub-devices. If a program binary has not been built for a sub-device, the program binary associated with the parent device will be used." Previously, each program or kernel object was created for a device. If a device was paritioned into sub-devices, the sub-devices may not have had an associated program/kernel object (unless one was explicitly built). Now, when shamrock queries a device for a kernel or program, it will search the device hierarchy and look for a parent device for which a program/kernel object may have been created. This patch enables the Khronos v1.2 test_device_partition to PASS. Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
-rw-r--r--src/core/cpu/device.h2
-rw-r--r--src/core/deviceinterface.h1
-rw-r--r--src/core/kernel.cpp17
-rw-r--r--src/core/program.cpp18
4 files changed, 34 insertions, 4 deletions
diff --git a/src/core/cpu/device.h b/src/core/cpu/device.h
index 52aa2d9..6dd2bce 100644
--- a/src/core/cpu/device.h
+++ b/src/core/cpu/device.h
@@ -105,6 +105,8 @@ class CPUDevice : public DeviceInterface
unsigned int numCPUs() const; /*!< \brief Number of cores in this (sub)device */
float cpuMhz() const; /*!< \brief Speed of the CPU in Mhz */
+ DeviceInterface * parentDevice() const { return p_parent_device; }
+
std::string builtinsHeader(void) const { return "cpu.h"; }
private:
diff --git a/src/core/deviceinterface.h b/src/core/deviceinterface.h
index 7bd16c7..2db5577 100644
--- a/src/core/deviceinterface.h
+++ b/src/core/deviceinterface.h
@@ -184,6 +184,7 @@ class DeviceInterface : public Object
return CL_SUCCESS;
}
+ virtual DeviceInterface * parentDevice() const = 0;
};
/**
diff --git a/src/core/kernel.cpp b/src/core/kernel.cpp
index 76ea5b9..f58f55a 100644
--- a/src/core/kernel.cpp
+++ b/src/core/kernel.cpp
@@ -80,13 +80,26 @@ Kernel::~Kernel()
}
}
+static bool matchDeviceOrParent(DeviceInterface *device_dep, DeviceInterface *device)
+{
+ bool match = (device_dep == device);
+ DeviceInterface *next_device = device->parentDevice();
+
+ // If no match, device could be a sub-device - so go up the hierarchy checking parents:
+ while (!match && next_device) {
+ match = (device_dep == next_device);
+ next_device = next_device->parentDevice();
+ }
+ return match;
+}
+
const Kernel::DeviceDependent &Kernel::deviceDependent(DeviceInterface *device) const
{
for (size_t i=0; i<p_device_dependent.size(); ++i)
{
const DeviceDependent &rs = p_device_dependent[i];
- if (rs.device == device || (!device && p_device_dependent.size() == 1))
+ if (matchDeviceOrParent(rs.device, device) || (!device && p_device_dependent.size() == 1))
return rs;
}
@@ -99,7 +112,7 @@ Kernel::DeviceDependent &Kernel::deviceDependent(DeviceInterface *device)
{
DeviceDependent &rs = p_device_dependent[i];
- if (rs.device == device || (!device && p_device_dependent.size() == 1))
+ if (matchDeviceOrParent(rs.device, device) || (!device && p_device_dependent.size() == 1))
return rs;
}
diff --git a/src/core/program.cpp b/src/core/program.cpp
index aa6e2ed..103a910 100644
--- a/src/core/program.cpp
+++ b/src/core/program.cpp
@@ -129,13 +129,27 @@ void Program::setDevices(cl_uint num_devices, DeviceInterface * const*devices)
}
}
+static bool matchDeviceOrParent(DeviceInterface *device_dep, DeviceInterface *device)
+{
+ bool match = (device_dep == device);
+ DeviceInterface *next_device = device->parentDevice();
+
+ // If no match, device could be a sub-device - so go up the hierarchy checking parents:
+ while (!match && next_device) {
+ match = (device_dep == next_device);
+ next_device = next_device->parentDevice();
+ }
+ return match;
+}
+
+
Program::DeviceDependent &Program::deviceDependent(DeviceInterface *device)
{
for (size_t i=0; i<p_device_dependent.size(); ++i)
{
DeviceDependent &rs = p_device_dependent[i];
- if (rs.device == device || (!device && p_device_dependent.size() == 1))
+ if (matchDeviceOrParent(rs.device, device) || (!device && p_device_dependent.size() == 1))
return rs;
}
@@ -148,7 +162,7 @@ const Program::DeviceDependent &Program::deviceDependent(DeviceInterface *device
{
const DeviceDependent &rs = p_device_dependent[i];
- if (rs.device == device || (!device && p_device_dependent.size() == 1))
+ if (matchDeviceOrParent(rs.device, device) || (!device && p_device_dependent.size() == 1))
return rs;
}