parent
bb88202879
commit
9b5fb27647
@ -1,49 +1,46 @@
|
|||||||
#include "paddle/majel/place.h"
|
#include "paddle/platform/place.h"
|
||||||
|
|
||||||
namespace majel {
|
namespace paddle {
|
||||||
|
namespace platform {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
class PlacePrinter : public boost::static_visitor<> {
|
class PlacePrinter : public boost::static_visitor<> {
|
||||||
private:
|
|
||||||
std::ostream& os_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlacePrinter(std::ostream& os) : os_(os) {}
|
PlacePrinter(std::ostream &os) : os_(os) {}
|
||||||
|
void operator()(const CpuPlace &) { os_ << "CpuPlace"; }
|
||||||
|
void operator()(const GpuPlace &p) { os_ << "GpuPlace(" << p.device << ")"; }
|
||||||
|
|
||||||
void operator()(const CpuPlace&) { os_ << "CpuPlace"; }
|
private:
|
||||||
|
std::ostream &os_;
|
||||||
void operator()(const GpuPlace& p) { os_ << "GpuPlace(" << p.device << ")"; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
static Place the_default_place;
|
static Place the_default_place;
|
||||||
|
|
||||||
void set_place(const Place& place) { the_default_place = place; }
|
void set_place(const Place &place) { the_default_place = place; }
|
||||||
|
const Place &get_place() { return the_default_place; }
|
||||||
const Place& get_place() { return the_default_place; }
|
|
||||||
|
|
||||||
const GpuPlace default_gpu() { return GpuPlace(0); }
|
const GpuPlace default_gpu() { return GpuPlace(0); }
|
||||||
|
|
||||||
const CpuPlace default_cpu() { return CpuPlace(); }
|
const CpuPlace default_cpu() { return CpuPlace(); }
|
||||||
|
|
||||||
bool is_gpu_place(const Place& p) {
|
bool is_gpu_place(const Place &p) {
|
||||||
return boost::apply_visitor(IsGpuPlace(), p);
|
return boost::apply_visitor(IsGpuPlace(), p);
|
||||||
}
|
}
|
||||||
|
bool is_cpu_place(const Place &p) {
|
||||||
bool is_cpu_place(const Place& p) {
|
|
||||||
return !boost::apply_visitor(IsGpuPlace(), p);
|
return !boost::apply_visitor(IsGpuPlace(), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool places_are_same_class(const Place& p1, const Place& p2) {
|
bool places_are_same_class(const Place &p1, const Place &p2) {
|
||||||
return is_gpu_place(p1) == is_gpu_place(p2);
|
return is_gpu_place(p1) == is_gpu_place(p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const majel::Place& p) {
|
std::ostream &operator<<(std::ostream &os, const Place &p) {
|
||||||
majel::detail::PlacePrinter printer(os);
|
detail::PlacePrinter printer(os);
|
||||||
boost::apply_visitor(printer, p);
|
boost::apply_visitor(printer, p);
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace majel
|
} // namespace platform
|
||||||
|
} // namespace paddle
|
||||||
|
Loading…
Reference in new issue