Commit b2e7d94e authored by Robert McGibbon's avatar Robert McGibbon
Browse files

Record plugin load failures

parent bca01957
...@@ -49,13 +49,13 @@ class KernelFactory; ...@@ -49,13 +49,13 @@ class KernelFactory;
* More precisely, a Platform object acts as a registry for a set of KernelFactory * More precisely, a Platform object acts as a registry for a set of KernelFactory
* objects which together implement the kernels. The Platform class, in turn, provides a * objects which together implement the kernels. The Platform class, in turn, provides a
* static registry of all available Platform objects. * static registry of all available Platform objects.
* *
* To get a Platform object, call * To get a Platform object, call
* *
* <pre> * <pre>
* Platform& platform Platform::findPlatform(kernelNames); * Platform& platform Platform::findPlatform(kernelNames);
* </pre> * </pre>
* *
* passing in the names of all kernels that will be required for the calculation you plan to perform. It * passing in the names of all kernels that will be required for the calculation you plan to perform. It
* will return the fastest available Platform which provides implementations of all the specified kernels. * will return the fastest available Platform which provides implementations of all the specified kernels.
* You can then call createKernel() to construct particular kernels as needed. * You can then call createKernel() to construct particular kernels as needed.
...@@ -133,14 +133,14 @@ public: ...@@ -133,14 +133,14 @@ public:
* Register a KernelFactory which should be used to create Kernels with a particular name. * Register a KernelFactory which should be used to create Kernels with a particular name.
* The Platform takes over ownership of the factory, and will delete it when the Platform itself * The Platform takes over ownership of the factory, and will delete it when the Platform itself
* is deleted. * is deleted.
* *
* @param name the kernel name for which the factory should be used * @param name the kernel name for which the factory should be used
* @param factory the factory to use for creating Kernels with the specified name * @param factory the factory to use for creating Kernels with the specified name
*/ */
void registerKernelFactory(const std::string& name, KernelFactory* factory); void registerKernelFactory(const std::string& name, KernelFactory* factory);
/** /**
* Determine whether this Platforms provides implementations of a set of kernels. * Determine whether this Platforms provides implementations of a set of kernels.
* *
* @param kernelNames the names of the kernels of interests * @param kernelNames the names of the kernels of interests
* @return true if this Platform provides implementations of all the kernels in the list, * @return true if this Platform provides implementations of all the kernels in the list,
* false if there are any which it does not support * false if there are any which it does not support
...@@ -151,9 +151,9 @@ public: ...@@ -151,9 +151,9 @@ public:
* the returned Kernels are independent and do not interact with each other. This means * the returned Kernels are independent and do not interact with each other. This means
* that it is possible to have multiple simulations in progress at one time without them * that it is possible to have multiple simulations in progress at one time without them
* interfering. * interfering.
* *
* If no KernelFactory has been registered for the specified name, this will throw an exception. * If no KernelFactory has been registered for the specified name, this will throw an exception.
* *
* @param name the name of the Kernel to get * @param name the name of the Kernel to get
* @param context the context for which to create a Kernel * @param context the context for which to create a Kernel
* @return a newly created Kernel object * @return a newly created Kernel object
...@@ -171,6 +171,10 @@ public: ...@@ -171,6 +171,10 @@ public:
* Get a registered Platform by index. * Get a registered Platform by index.
*/ */
static Platform& getPlatform(int index); static Platform& getPlatform(int index);
/**
* Get any failures caused during the last call to loadPluginsFromDirectory
*/
static std::vector<std::string> getLoadFailures();
/** /**
* Get the registered Platform with a particular name. If no Platform with that name has been * Get the registered Platform with a particular name. If no Platform with that name has been
* registered, this throws an exception. * registered, this throws an exception.
...@@ -178,7 +182,7 @@ public: ...@@ -178,7 +182,7 @@ public:
static Platform& getPlatformByName(const std::string& name); static Platform& getPlatformByName(const std::string& name);
/** /**
* Find a Platform which can be used to perform a calculation. * Find a Platform which can be used to perform a calculation.
* *
* @param kernelNames the names of all kernels which will be needed for the calculation * @param kernelNames the names of all kernels which will be needed for the calculation
* @return the fastest registered Platform which supports all of the requested kernels. If no * @return the fastest registered Platform which supports all of the requested kernels. If no
* Platform exists which supports all of them, this will throw an exception. * Platform exists which supports all of them, this will throw an exception.
...@@ -233,8 +237,10 @@ private: ...@@ -233,8 +237,10 @@ private:
std::map<std::string, KernelFactory*> kernelFactories; std::map<std::string, KernelFactory*> kernelFactories;
std::map<std::string, std::string> defaultProperties; std::map<std::string, std::string> defaultProperties;
static std::vector<Platform*>& getPlatforms(); static std::vector<Platform*>& getPlatforms();
static std::vector<std::string> loadFailures;
}; };
} // namespace OpenMM } // namespace OpenMM
#endif /*OPENMM_PLATFORM_H_*/ #endif /*OPENMM_PLATFORM_H_*/
...@@ -51,6 +51,9 @@ ...@@ -51,6 +51,9 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
std::vector<std::string> Platform::loadFailures;
static int registerPlatforms() { static int registerPlatforms() {
// Register the Platforms built into the main library. This should eventually be moved elsewhere. // Register the Platforms built into the main library. This should eventually be moved elsewhere.
...@@ -140,6 +143,10 @@ Platform& Platform::getPlatform(int index) { ...@@ -140,6 +143,10 @@ Platform& Platform::getPlatform(int index) {
throw OpenMMException("Invalid platform index"); throw OpenMMException("Invalid platform index");
} }
std::vector<std::string> Platform::getLoadFailures() {
return loadFailures;
}
Platform& Platform::getPlatformByName(const string& name) { Platform& Platform::getPlatformByName(const string& name) {
for (int i = 0; i < getNumPlatforms(); i++) for (int i = 0; i < getNumPlatforms(); i++)
if (getPlatform(i).getName() == name) if (getPlatform(i).getName() == name)
...@@ -196,8 +203,9 @@ static void* loadOneLibrary(const string& file) { ...@@ -196,8 +203,9 @@ static void* loadOneLibrary(const string& file) {
throw OpenMMException("Loading dynamic libraries is not supported on PNaCl"); throw OpenMMException("Loading dynamic libraries is not supported on PNaCl");
#else #else
void *handle = dlopen(file.c_str(), RTLD_LAZY | RTLD_GLOBAL); void *handle = dlopen(file.c_str(), RTLD_LAZY | RTLD_GLOBAL);
if (handle == NULL) if (handle == NULL) {
throw OpenMMException("Error loading library "+file+": "+dlerror()); throw OpenMMException("Error loading library "+file+": "+dlerror());
}
return handle; return handle;
#endif #endif
} }
...@@ -261,12 +269,14 @@ vector<string> Platform::loadPluginsFromDirectory(const string& directory) { ...@@ -261,12 +269,14 @@ vector<string> Platform::loadPluginsFromDirectory(const string& directory) {
vector<void*> plugins; vector<void*> plugins;
#endif #endif
vector<string> loadedLibraries; vector<string> loadedLibraries;
loadFailures.resize(0);
for (unsigned int i = 0; i < files.size(); ++i) { for (unsigned int i = 0; i < files.size(); ++i) {
try { try {
plugins.push_back(loadOneLibrary(directory+dirSeparator+files[i])); plugins.push_back(loadOneLibrary(directory+dirSeparator+files[i]));
loadedLibraries.push_back(files[i]); loadedLibraries.push_back(files[i]);
} catch (OpenMMException& ex) { } catch (OpenMMException& ex) {
// Just ignore it. loadFailures.push_back(ex.what());
} }
} }
initializePlugins(plugins); initializePlugins(plugins);
......
...@@ -180,6 +180,7 @@ UNITS = { ...@@ -180,6 +180,7 @@ UNITS = {
("*", "getParticleMass") : ("unit.amu", ()), ("*", "getParticleMass") : ("unit.amu", ()),
("*", "getPlatform") : (None, ()), ("*", "getPlatform") : (None, ()),
("*", "getPlatformByName") : (None, ()), ("*", "getPlatformByName") : (None, ()),
("*", "getLoadFailures"): (None, ()),
("*", "getRandomNumberSeed") : (None, ()), ("*", "getRandomNumberSeed") : (None, ()),
("*", "getReactionFieldDielectric") : (None, ()), ("*", "getReactionFieldDielectric") : (None, ()),
("*", "getSoluteDielectric") : (None, ()), ("*", "getSoluteDielectric") : (None, ()),
......
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