aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
}