"platforms/vscode:/vscode.git/clone" did not exist on "2ffa7cd36e2f19100ea233cf5e618bacd62e8e3d"
Commit 0f83704f authored by Peter Eastman's avatar Peter Eastman
Browse files

Added platform properties to report the CUDA/OpenCL device name and OpenCL platform name

parent 4d75af9f
...@@ -62,6 +62,13 @@ public: ...@@ -62,6 +62,13 @@ public:
static const std::string key = "CudaDeviceIndex"; static const std::string key = "CudaDeviceIndex";
return key; return key;
} }
/**
* This is the name of the parameter that reports the CUDA device or devices being used.
*/
static const std::string& CudaDeviceName() {
static const std::string key = "CudaDeviceName";
return key;
}
/** /**
* This is the name of the parameter for selecting whether CUDA should sync or spin loop while waiting for results. * This is the name of the parameter for selecting whether CUDA should sync or spin loop while waiting for results.
*/ */
......
...@@ -42,6 +42,13 @@ ...@@ -42,6 +42,13 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
#define CHECK_RESULT(result, prefix) \
if (result != CUDA_SUCCESS) { \
std::stringstream m; \
m<<prefix<<": "<<CudaContext::getErrorString(result)<<" ("<<result<<")"<<" at "<<__FILE__<<":"<<__LINE__; \
throw OpenMMException(m.str());\
}
extern "C" OPENMM_EXPORT_CUDA void registerPlatforms() { extern "C" OPENMM_EXPORT_CUDA void registerPlatforms() {
Platform::registerPlatform(new CudaPlatform()); Platform::registerPlatform(new CudaPlatform());
} }
...@@ -77,11 +84,13 @@ CudaPlatform::CudaPlatform() { ...@@ -77,11 +84,13 @@ CudaPlatform::CudaPlatform() {
registerKernelFactory(ApplyMonteCarloBarostatKernel::Name(), factory); registerKernelFactory(ApplyMonteCarloBarostatKernel::Name(), factory);
registerKernelFactory(RemoveCMMotionKernel::Name(), factory); registerKernelFactory(RemoveCMMotionKernel::Name(), factory);
platformProperties.push_back(CudaDeviceIndex()); platformProperties.push_back(CudaDeviceIndex());
platformProperties.push_back(CudaDeviceName());
platformProperties.push_back(CudaUseBlockingSync()); platformProperties.push_back(CudaUseBlockingSync());
platformProperties.push_back(CudaPrecision()); platformProperties.push_back(CudaPrecision());
platformProperties.push_back(CudaCompiler()); platformProperties.push_back(CudaCompiler());
platformProperties.push_back(CudaTempDirectory()); platformProperties.push_back(CudaTempDirectory());
setPropertyDefaultValue(CudaDeviceIndex(), ""); setPropertyDefaultValue(CudaDeviceIndex(), "");
setPropertyDefaultValue(CudaDeviceName(), "");
setPropertyDefaultValue(CudaUseBlockingSync(), "true"); setPropertyDefaultValue(CudaUseBlockingSync(), "true");
setPropertyDefaultValue(CudaPrecision(), "single"); setPropertyDefaultValue(CudaPrecision(), "single");
#ifdef _MSC_VER #ifdef _MSC_VER
...@@ -161,13 +170,19 @@ CudaPlatform::PlatformData::PlatformData(const System& system, const string& dev ...@@ -161,13 +170,19 @@ CudaPlatform::PlatformData::PlatformData(const System& system, const string& dev
} }
if (contexts.size() == 0) if (contexts.size() == 0)
contexts.push_back(new CudaContext(system, -1, blocking, precisionProperty, compilerProperty, tempProperty, *this)); contexts.push_back(new CudaContext(system, -1, blocking, precisionProperty, compilerProperty, tempProperty, *this));
stringstream device; stringstream deviceIndex, deviceName;
for (int i = 0; i < (int) contexts.size(); i++) { for (int i = 0; i < (int) contexts.size(); i++) {
if (i > 0) if (i > 0) {
device << ','; deviceIndex << ',';
device << contexts[i]->getDeviceIndex(); deviceName << ',';
}
deviceIndex << contexts[i]->getDeviceIndex();
char name[1000];
CHECK_RESULT(cuDeviceGetName(name, 1000, contexts[i]->getDevice()), "Error querying device name");
deviceName << name;
} }
propertyValues[CudaPlatform::CudaDeviceIndex()] = device.str(); propertyValues[CudaPlatform::CudaDeviceIndex()] = deviceIndex.str();
propertyValues[CudaPlatform::CudaDeviceName()] = deviceName.str();
propertyValues[CudaPlatform::CudaUseBlockingSync()] = blocking ? "true" : "false"; propertyValues[CudaPlatform::CudaUseBlockingSync()] = blocking ? "true" : "false";
propertyValues[CudaPlatform::CudaPrecision()] = precisionProperty; propertyValues[CudaPlatform::CudaPrecision()] = precisionProperty;
propertyValues[CudaPlatform::CudaCompiler()] = compilerProperty; propertyValues[CudaPlatform::CudaCompiler()] = compilerProperty;
......
...@@ -61,6 +61,13 @@ public: ...@@ -61,6 +61,13 @@ public:
static const std::string key = "OpenCLDeviceIndex"; static const std::string key = "OpenCLDeviceIndex";
return key; return key;
} }
/**
* This is the name of the parameter that reports the OpenCL device or devices being used.
*/
static const std::string& OpenCLDeviceName() {
static const std::string key = "OpenCLDeviceName";
return key;
}
/** /**
* This is the name of the parameter for selecting which OpenCL platform to use. * This is the name of the parameter for selecting which OpenCL platform to use.
*/ */
...@@ -68,6 +75,13 @@ public: ...@@ -68,6 +75,13 @@ public:
static const std::string key = "OpenCLPlatformIndex"; static const std::string key = "OpenCLPlatformIndex";
return key; return key;
} }
/**
* This is the name of the parameter that reports the OpenCL platform being used.
*/
static const std::string& OpenCLPlatformName() {
static const std::string key = "OpenCLPlatformName";
return key;
}
/** /**
* This is the name of the parameter for selecting what numerical precision to use. * This is the name of the parameter for selecting what numerical precision to use.
*/ */
......
...@@ -74,10 +74,14 @@ OpenCLPlatform::OpenCLPlatform() { ...@@ -74,10 +74,14 @@ OpenCLPlatform::OpenCLPlatform() {
registerKernelFactory(ApplyMonteCarloBarostatKernel::Name(), factory); registerKernelFactory(ApplyMonteCarloBarostatKernel::Name(), factory);
registerKernelFactory(RemoveCMMotionKernel::Name(), factory); registerKernelFactory(RemoveCMMotionKernel::Name(), factory);
platformProperties.push_back(OpenCLDeviceIndex()); platformProperties.push_back(OpenCLDeviceIndex());
platformProperties.push_back(OpenCLDeviceName());
platformProperties.push_back(OpenCLPlatformIndex()); platformProperties.push_back(OpenCLPlatformIndex());
platformProperties.push_back(OpenCLPlatformName());
platformProperties.push_back(OpenCLPrecision()); platformProperties.push_back(OpenCLPrecision());
setPropertyDefaultValue(OpenCLDeviceIndex(), ""); setPropertyDefaultValue(OpenCLDeviceIndex(), "");
setPropertyDefaultValue(OpenCLDeviceName(), "");
setPropertyDefaultValue(OpenCLPlatformIndex(), ""); setPropertyDefaultValue(OpenCLPlatformIndex(), "");
setPropertyDefaultValue(OpenCLPlatformName(), "");
setPropertyDefaultValue(OpenCLPrecision(), "single"); setPropertyDefaultValue(OpenCLPrecision(), "single");
} }
...@@ -133,14 +137,21 @@ OpenCLPlatform::PlatformData::PlatformData(const System& system, const string& p ...@@ -133,14 +137,21 @@ OpenCLPlatform::PlatformData::PlatformData(const System& system, const string& p
} }
if (contexts.size() == 0) if (contexts.size() == 0)
contexts.push_back(new OpenCLContext(system, platformIndex, -1, precisionProperty, *this)); contexts.push_back(new OpenCLContext(system, platformIndex, -1, precisionProperty, *this));
stringstream device; stringstream deviceIndex, deviceName;
for (int i = 0; i < (int) contexts.size(); i++) { for (int i = 0; i < (int) contexts.size(); i++) {
if (i > 0) if (i > 0) {
device << ','; deviceIndex << ',';
device << contexts[i]->getDeviceIndex(); deviceName << ',';
}
deviceIndex << contexts[i]->getDeviceIndex();
deviceName << contexts[i]->getDevice().getInfo<CL_DEVICE_NAME>();
} }
propertyValues[OpenCLPlatform::OpenCLDeviceIndex()] = device.str(); propertyValues[OpenCLPlatform::OpenCLDeviceIndex()] = deviceIndex.str();
propertyValues[OpenCLPlatform::OpenCLDeviceName()] = deviceName.str();
propertyValues[OpenCLPlatform::OpenCLPlatformIndex()] = contexts[0]->intToString(platformIndex); propertyValues[OpenCLPlatform::OpenCLPlatformIndex()] = contexts[0]->intToString(platformIndex);
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
propertyValues[OpenCLPlatform::OpenCLPlatformName()] = platforms[platformIndex].getInfo<CL_PLATFORM_NAME>();
propertyValues[OpenCLPlatform::OpenCLPrecision()] = precisionProperty; propertyValues[OpenCLPlatform::OpenCLPrecision()] = precisionProperty;
contextEnergy.resize(contexts.size()); contextEnergy.resize(contexts.size());
} }
......
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