[asl] 35/177: Choosing first found device in the Hardware class by default
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Aug 27 09:22:36 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository asl.
commit 4aa24bde5b027439dc22d3d32a89ad7a03dd9353
Author: AvtechScientific <AvtechScientific at users.noreply.github.com>
Date: Thu Jun 18 16:16:48 2015 +0300
Choosing first found device in the Hardware class by default
---
src/acl/aclHardware.cxx | 73 +++++++++++++++++++++++++++++++++----------------
src/acl/aclHardware.h | 13 +++++++--
2 files changed, 60 insertions(+), 26 deletions(-)
diff --git a/src/acl/aclHardware.cxx b/src/acl/aclHardware.cxx
index ee52d0f..340f15e 100644
--- a/src/acl/aclHardware.cxx
+++ b/src/acl/aclHardware.cxx
@@ -45,16 +45,13 @@ namespace acl
const vector<TypeID> TYPE_SELECT({TYPE_INT, TYPE_INT, TYPE_INT, TYPE_LONG, TYPE_LONG});
Hardware hardware;
-
+
+
Hardware::Hardware():
- devicesInfo(""),
- defaultPlatform(""),
- defaultDevice("")
+ devicesInfo("\n\n# List of all available devices\n"),
+ defaultDeviceInfo("")
{
- loadConfiguration();
-
-
- // Have a look at the available platforms and their devices
+ // Scan all available platforms and their devices
vector<cl::Platform> platforms;
vector<cl::Device> devices;
cl_context_properties cps[3];
@@ -70,8 +67,8 @@ namespace acl
{
status = platforms[i].getDevices(CL_DEVICE_TYPE_ALL, &devices);
errorMessage(status, "Platform::getDevices()");
- devicesInfo += "Platform: " + platforms[i].getInfo<CL_PLATFORM_VENDOR>()
- + "\nNumber of devices: " + numToStr(devices.size()) + "\n";
+ devicesInfo += "# Platform: " + platforms[i].getInfo<CL_PLATFORM_VENDOR>()
+ + "\n# Number of devices: " + numToStr(devices.size()) + "\n";
cps[0] = CL_CONTEXT_PLATFORM;
cps[1] = (cl_context_properties)(platforms[i])();
@@ -87,40 +84,68 @@ namespace acl
queues.push_back(CommandQueue(new cl::CommandQueue(context, devices[j], 0, &status)));
errorMessage(status, "CommandQueue::CommandQueue()");
- if ((platforms[i].getInfo<CL_PLATFORM_VENDOR>().c_str() == defaultPlatform) &&
- (devices[j].getInfo<CL_DEVICE_NAME>().c_str() == defaultDevice))
- {
- // Choose requested device on requested platform
- defaultQueue = queues.back();
- }
-
- devicesInfo += "\t" + devices[j].getInfo<CL_DEVICE_NAME>() + "\n";
+ devicesInfo += "# \t" + devices[j].getInfo<CL_DEVICE_NAME>() + "\n";
}
}
}
-
+
+ // Set first found queue as default queue
+ defaultQueue = queues.front();
+ setDefaultDeviceInfo();
+ }
+
+
+ void Hardware::setDefaultQueue(const std::string & platform,
+ const std::string & device)
+ {
+ defaultQueue = NULL;
+
+ for (unsigned int i(0); i < queues.size(); ++i)
+ {
+ if ((platform == getPlatformVendor(queues[i])) &&
+ (device == getDeviceName(queues[i])))
+ {
+ // Choose requested device on requested platform
+ defaultQueue = queues.back();
+ setDefaultDeviceInfo();
+ }
+ }
+
+ // Warn if requested combination of platform and device was not found
if (defaultQueue.get() == 0)
{
- devicesInfo += "\n" + warningString("Requested device not found") + "\n";
// Choose first available device
defaultQueue = queues.front();
+ setDefaultDeviceInfo();
+ warningMessage("Requested device not found! Using:\n" + defaultDeviceInfo);
}
+ }
- // get platform and device info from defaultQueue
- devicesInfo += "\nDefault device: " + getPlatformVendor(defaultQueue)
- + ", " + getDeviceName(defaultQueue) + "\n";
+
+ void Hardware::setDefaultDeviceInfo()
+ {
+ defaultDeviceInfo = "# Default computation device";
+ defaultDeviceInfo += "\nplatform = " + getPlatformVendor(defaultQueue)
+ + "\ndevice = " + getDeviceName(defaultQueue);
+ }
+
+
+ std::string Hardware::getDefaultDeviceInfo()
+ {
+ return defaultDeviceInfo;
}
void Hardware::loadConfiguration(const string & fileName)
{
- ParametersManager parametersManager;
+/* ParametersManager parametersManager;
Parameter<string> platform("", "platform", "Default platform", "");
Parameter<string> device("", "device", "Default device", "");
parametersManager.load(fileName);
defaultPlatform = platform.v();
defaultDevice = device.v();
+*/
}
diff --git a/src/acl/aclHardware.h b/src/acl/aclHardware.h
index 4720d7c..5ab3100 100644
--- a/src/acl/aclHardware.h
+++ b/src/acl/aclHardware.h
@@ -132,15 +132,24 @@ namespace acl
public:
/// OpenCL related initializations are done here.
/// Context, Device list, Command Queue are set up.
+ /// Default computation queue is set to the first found device.
Hardware();
+ /// Sets default computation queue
+ /// identified by \p platform and \p device.
+ /// Warns if requested combination is not found.
+ void setDefaultQueue(const std::string & platform = "",
+ const std::string & device = "");
+// remove it after merging asl.ini with parameters.ini?
void loadConfiguration(const std::string & fileName = "asl.ini");
std::vector<CommandQueue> queues;
CommandQueue defaultQueue;
std::string getDevicesInfo();
+ std::string getDefaultDeviceInfo();
private:
+ // Sets defaultDeviceInfo based on current defaultQueue
+ void setDefaultDeviceInfo();
std::string devicesInfo;
- std::string defaultPlatform;
- std::string defaultDevice;
+ std::string defaultDeviceInfo;
};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/asl.git
More information about the debian-science-commits
mailing list