Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merged exclusive.hpp into devlist.hpp

VexCL depends on boost anyway now.
  • Loading branch information...
commit 5453d4b060be8148588ce21bd22f4819b817bef9 1 parent 61d1d65
@ddemidov authored
View
1  examples/exclusive.cpp
@@ -1,5 +1,4 @@
#include <vexcl/vexcl.hpp>
-#include <vexcl/exclusive.hpp>
using namespace vex;
int main() {
View
2  examples/symbolic.cpp
@@ -5,8 +5,6 @@
//#define VEXCL_SHOW_KERNELS
#include <vexcl/vexcl.hpp>
-#include <vexcl/exclusive.hpp>
-#include <vexcl/generator.hpp>
// http://headmyshoulder.github.com/odeint-v2
#include <boost/numeric/odeint.hpp>
View
98 vexcl/devlist.hpp
@@ -39,9 +39,11 @@ THE SOFTWARE.
#include <vector>
#include <string>
+#include <fstream>
#include <tuple>
#include <cstdlib>
#include <vexcl/util.hpp>
+#include <boost/interprocess/sync/file_lock.hpp>
namespace vex {
@@ -212,6 +214,102 @@ namespace Filter {
const EnvFilter Env;
+ /// \internal Exclusive access to selected devices.
+ template <class Filter>
+ class ExclusiveFilter {
+ private:
+ const Filter &filter;
+
+ static std::map<cl_device_id, std::string> get_uids() {
+ std::map<cl_device_id, std::string> uids;
+
+ std::vector<cl::Platform> platform;
+ cl::Platform::get(&platform);
+
+ const char *lock_dir = getenv("VEXCL_LOCK_DIR");
+
+ for(size_t p_id = 0; p_id < platform.size(); p_id++) {
+ std::vector<cl::Device> device;
+
+ platform[p_id].getDevices(CL_DEVICE_TYPE_ALL, &device);
+
+ for(size_t d_id = 0; d_id < device.size(); d_id++) {
+ std::ostringstream id;
+#ifdef WIN32
+ id << (lock_dir ? lock_dir : getenv("TEMP")) << "\\";
+#else
+ id << (lock_dir ? lock_dir : "/tmp") << "/";
+#endif
+ id << "vexcl_device_" << p_id << "_" << d_id << ".lock";
+
+ uids[device[d_id]()] = id.str();
+ }
+ }
+
+ return uids;
+ }
+
+ struct locker {
+ locker(std::string fname) : file(fname)
+ {
+ if (!file.is_open() || file.fail()) {
+ std::cerr
+ << "WARNING: failed to open file \"" << fname << "\"\n"
+ << " Check that target directory is exists and is writable.\n"
+ << " Exclusive mode is off.\n"
+ << std::endl;
+ } else {
+ flock.reset(new boost::interprocess::file_lock(fname.c_str()));
+ }
+ }
+
+ bool try_lock() {
+ if (flock)
+ return flock->try_lock();
+ else
+ return true;
+ }
+
+ std::ofstream file;
+ std::unique_ptr<boost::interprocess::file_lock> flock;
+ };
+ public:
+ ExclusiveFilter(const Filter &filter) : filter(filter) {}
+
+ bool operator()(const cl::Device &d) const {
+ static std::map<cl_device_id, std::string> dev_uids = get_uids();
+ static std::vector<std::unique_ptr<locker>> locks;
+
+ std::unique_ptr<locker> lck(new locker(dev_uids[d()]));
+
+ if (lck->try_lock() && filter(d)) {
+ locks.push_back(std::move(lck));
+ return true;
+ }
+
+ return false;
+ }
+
+ };
+
+ /// Allows exclusive access to compute devices across several processes.
+ /**
+ * Returns devices that pass through provided device filter and are not
+ * locked.
+ *
+ * \param filter Compute device filter
+ *
+ * \note Depends on boost::interprocess library.
+ *
+ * lock files are created in directory specified in VEXCL_LOCK_DIR
+ * environment variable. If the variable does not exist, /tmp is
+ * used on Linux and %TMPDIR% on Windows. The lock directory should exist
+ * and be writable by the running user.
+ */
+ template <class Filter>
+ ExclusiveFilter<Filter> Exclusive(const Filter &filter) {
+ return ExclusiveFilter<Filter>(filter);
+ }
/// Negation of a filter.
template <class Flt>
struct NegateFilter {
View
155 vexcl/exclusive.hpp
@@ -1,155 +0,0 @@
-#ifndef VEXCL_EXCLUSIVE_HPP
-#define VEXCLEXCLUSIVE_HPP
-
-/*
-The MIT License
-
-Copyright (c) 2012 Denis Demidov <ddemidov@ksu.ru>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-/**
- * \file exclusive.hpp
- * \author Denis Demidov <ddemidov@ksu.ru>
- * \brief Device filter allowing exclusive access
- *
- * \note This file should be included manually since it depends on
- * boost::interprocess library.
- */
-
-#include <vector>
-#include <string>
-#include <fstream>
-#include <memory>
-#include <cstdlib>
-#include <boost/interprocess/sync/file_lock.hpp>
-
-#ifndef __CL_ENABLE_EXCEPTIONS
-# define __CL_ENABLE_EXCEPTIONS
-#endif
-#include <CL/cl.hpp>
-
-namespace vex {
-
-/// Device filters.
-namespace Filter {
-
- /// \internal Exclusive access to selected devices.
- template <class Filter>
- class ExclusiveFilter {
- private:
- const Filter &filter;
-
- static std::map<cl_device_id, std::string> get_uids() {
- std::map<cl_device_id, std::string> uids;
-
- std::vector<cl::Platform> platform;
- cl::Platform::get(&platform);
-
- const char *lock_dir = getenv("VEXCL_LOCK_DIR");
-
- for(size_t p_id = 0; p_id < platform.size(); p_id++) {
- std::vector<cl::Device> device;
-
- platform[p_id].getDevices(CL_DEVICE_TYPE_ALL, &device);
-
- for(size_t d_id = 0; d_id < device.size(); d_id++) {
- std::ostringstream id;
-#ifdef WIN32
- id << (lock_dir ? lock_dir : getenv("TEMP")) << "\\";
-#else
- id << (lock_dir ? lock_dir : "/tmp") << "/";
-#endif
- id << "vexcl_device_" << p_id << "_" << d_id << ".lock";
-
- uids[device[d_id]()] = id.str();
- }
- }
-
- return uids;
- }
-
- struct locker {
- locker(std::string fname) : file(fname)
- {
- if (!file.is_open() || file.fail()) {
- std::cerr
- << "WARNING: failed to open file \"" << fname << "\"\n"
- << " Check that target directory is exists and is writable.\n"
- << " Exclusive mode is off.\n"
- << std::endl;
- } else {
- flock.reset(new boost::interprocess::file_lock(fname.c_str()));
- }
- }
-
- bool try_lock() {
- if (flock)
- return flock->try_lock();
- else
- return true;
- }
-
- std::ofstream file;
- std::unique_ptr<boost::interprocess::file_lock> flock;
- };
- public:
- ExclusiveFilter(const Filter &filter) : filter(filter) {}
-
- bool operator()(const cl::Device &d) const {
- static std::map<cl_device_id, std::string> dev_uids = get_uids();
- static std::vector<std::unique_ptr<locker>> locks;
-
- std::unique_ptr<locker> lck(new locker(dev_uids[d()]));
-
- if (lck->try_lock() && filter(d)) {
- locks.push_back(std::move(lck));
- return true;
- }
-
- return false;
- }
-
- };
-
- /// Allows exclusive access to compute devices across several processes.
- /**
- * Returns devices that pass through provided device filter and are not
- * locked.
- *
- * \param filter Compute device filter
- *
- * \note Depends on boost::interprocess library.
- *
- * lock files are created in directory specified in VEXCL_LOCK_DIR
- * environment variable. If the variable does not exist, /tmp is
- * used on Linux and %TMPDIR% on Windows. The lock directory should exist
- * and be writable by the running user.
- */
- template <class Filter>
- ExclusiveFilter<Filter> Exclusive(const Filter &filter) {
- return ExclusiveFilter<Filter>(filter);
- }
-}
-
-}
-
-
-#endif
View
50 vexcl/vector.hpp
@@ -54,6 +54,30 @@ namespace vex {
//--- Partitioning ----------------------------------------------------------
+/// Weights device wrt to vector performance.
+/**
+ * Launches the following kernel on each device:
+ * \code
+ * a = b + c;
+ * \endcode
+ * where a, b and c are device vectors. Each device gets portion of the vector
+ * proportional to the performance of this operation.
+ */
+inline double device_vector_perf(
+ const cl::Context &context, const cl::Device &device
+ );
+
+/// Assigns equal weight to each device.
+/**
+ * This results in equal partitioning.
+ */
+inline double equal_weights(
+ const cl::Context &context, const cl::Device &device
+ )
+{
+ return 1;
+}
+
/// \cond INTERNAL
template <bool dummy = true>
@@ -136,30 +160,6 @@ typename partitioning_scheme<dummy>::weight_function partitioning_scheme<dummy>:
/// \endcond
-/// Weights device wrt to vector performance.
-/**
- * Launches the following kernel on each device:
- * \code
- * a = b + c;
- * \endcode
- * where a, b and c are device vectors. Each device gets portion of the vector
- * proportional to the performance of this operation.
- */
-inline double device_vector_perf(
- const cl::Context &context, const cl::Device &device
- );
-
-/// Assigns equal weight to each device.
-/**
- * This results in equal partitioning.
- */
-inline double equal_weights(
- const cl::Context &context, const cl::Device &device
- )
-{
- return 1;
-}
-
/// Partitioning scheme for vectors and matrices.
/**
* Should be set once before any object of vector or matrix type is declared.
@@ -170,7 +170,7 @@ inline void set_partitioning(
std::function< double(const cl::Context&, const cl::Device&) > f
)
{
- parttioning<>::set(f);
+ partitioning_scheme<>::set(f);
}
inline std::vector<size_t> partition(size_t n,
View
1  vexcl/vexcl.hpp
@@ -484,6 +484,7 @@ there, you can download it from <a href="http://www.khronos.org/registry/cl">Kro
#include <vexcl/reduce.hpp>
#include <vexcl/spmat.hpp>
#include <vexcl/stencil.hpp>
+#include <vexcl/generator.hpp>
#include <vexcl/profiler.hpp>
#ifdef WIN32
Please sign in to comment.
Something went wrong with that request. Please try again.