|
|
@ -2,40 +2,38 @@
|
|
|
|
#include <boost/variant.hpp>
|
|
|
|
#include <boost/variant.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
|
|
namespace majel {
|
|
|
|
namespace paddle {
|
|
|
|
|
|
|
|
namespace platform {
|
|
|
|
|
|
|
|
|
|
|
|
struct CpuPlace {
|
|
|
|
struct CpuPlace {
|
|
|
|
CpuPlace() {} // WORKAROUND: for some reason, omitting this constructor
|
|
|
|
// WORKAROUND: for some reason, omitting this constructor
|
|
|
|
// causes errors with boost 1.59 and OSX
|
|
|
|
// causes errors with boost 1.59 and OSX
|
|
|
|
|
|
|
|
CpuPlace() {}
|
|
|
|
|
|
|
|
|
|
|
|
// needed for variant equality comparison
|
|
|
|
// needed for variant equality comparison
|
|
|
|
inline bool operator==(const CpuPlace &) const { return true; }
|
|
|
|
inline bool operator==(const CpuPlace &) const { return true; }
|
|
|
|
|
|
|
|
|
|
|
|
inline bool operator!=(const CpuPlace &) const { return false; }
|
|
|
|
inline bool operator!=(const CpuPlace &) const { return false; }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct GpuPlace {
|
|
|
|
struct GpuPlace {
|
|
|
|
|
|
|
|
GpuPlace() : GpuPlace(0) {}
|
|
|
|
GpuPlace(int d) : device(d) {}
|
|
|
|
GpuPlace(int d) : device(d) {}
|
|
|
|
|
|
|
|
|
|
|
|
// needed for variant equality comparison
|
|
|
|
// needed for variant equality comparison
|
|
|
|
inline bool operator==(const GpuPlace &o) const { return device == o.device; }
|
|
|
|
inline bool operator==(const GpuPlace &o) const { return device == o.device; }
|
|
|
|
|
|
|
|
|
|
|
|
inline bool operator!=(const GpuPlace &o) const { return !(*this == o); }
|
|
|
|
inline bool operator!=(const GpuPlace &o) const { return !(*this == o); }
|
|
|
|
|
|
|
|
|
|
|
|
GpuPlace() : GpuPlace(0) {}
|
|
|
|
|
|
|
|
int device;
|
|
|
|
int device;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class IsGpuPlace : public boost::static_visitor<bool> {
|
|
|
|
struct IsGpuPlace : public boost::static_visitor<bool> {
|
|
|
|
public:
|
|
|
|
|
|
|
|
bool operator()(const CpuPlace &) const { return false; }
|
|
|
|
bool operator()(const CpuPlace &) const { return false; }
|
|
|
|
|
|
|
|
|
|
|
|
bool operator()(const GpuPlace &gpu) const { return true; }
|
|
|
|
bool operator()(const GpuPlace &gpu) const { return true; }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef boost::variant<GpuPlace, CpuPlace> Place;
|
|
|
|
typedef boost::variant<GpuPlace, CpuPlace> Place;
|
|
|
|
|
|
|
|
|
|
|
|
void set_place(const Place &);
|
|
|
|
void set_place(const Place &);
|
|
|
|
|
|
|
|
|
|
|
|
const Place &get_place();
|
|
|
|
const Place &get_place();
|
|
|
|
|
|
|
|
|
|
|
|
const GpuPlace default_gpu();
|
|
|
|
const GpuPlace default_gpu();
|
|
|
@ -45,6 +43,7 @@ bool is_gpu_place(const Place&);
|
|
|
|
bool is_cpu_place(const Place &);
|
|
|
|
bool is_cpu_place(const Place &);
|
|
|
|
bool places_are_same_class(const Place &, const Place &);
|
|
|
|
bool places_are_same_class(const Place &, const Place &);
|
|
|
|
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream&, const majel::Place&);
|
|
|
|
std::ostream &operator<<(std::ostream &, const Place &);
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace majel
|
|
|
|
} // namespace platform
|
|
|
|
|
|
|
|
} // namespace paddle
|
|
|
|