You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.1 KiB
50 lines
1.1 KiB
8 years ago
|
#include "paddle/majel/place.h"
|
||
8 years ago
|
|
||
|
namespace majel {
|
||
|
|
||
|
namespace detail {
|
||
|
|
||
8 years ago
|
class PlacePrinter : public boost::static_visitor<> {
|
||
8 years ago
|
private:
|
||
8 years ago
|
std::ostream& os_;
|
||
|
|
||
8 years ago
|
public:
|
||
8 years ago
|
PlacePrinter(std::ostream& os) : os_(os) {}
|
||
8 years ago
|
|
||
8 years ago
|
void operator()(const CpuPlace&) { os_ << "CpuPlace"; }
|
||
8 years ago
|
|
||
8 years ago
|
void operator()(const GpuPlace& p) { os_ << "GpuPlace(" << p.device << ")"; }
|
||
8 years ago
|
};
|
||
|
|
||
8 years ago
|
} // namespace detail
|
||
8 years ago
|
|
||
|
static Place the_default_place;
|
||
|
|
||
8 years ago
|
void set_place(const Place& place) { the_default_place = place; }
|
||
8 years ago
|
|
||
8 years ago
|
const Place& get_place() { return the_default_place; }
|
||
8 years ago
|
|
||
8 years ago
|
const GpuPlace default_gpu() { return GpuPlace(0); }
|
||
8 years ago
|
|
||
8 years ago
|
const CpuPlace default_cpu() { return CpuPlace(); }
|
||
8 years ago
|
|
||
|
bool is_gpu_place(const Place& p) {
|
||
8 years ago
|
return boost::apply_visitor(IsGpuPlace(), p);
|
||
8 years ago
|
}
|
||
|
|
||
|
bool is_cpu_place(const Place& p) {
|
||
8 years ago
|
return !boost::apply_visitor(IsGpuPlace(), p);
|
||
8 years ago
|
}
|
||
|
|
||
|
bool places_are_same_class(const Place& p1, const Place& p2) {
|
||
8 years ago
|
return is_gpu_place(p1) == is_gpu_place(p2);
|
||
8 years ago
|
}
|
||
|
|
||
|
std::ostream& operator<<(std::ostream& os, const majel::Place& p) {
|
||
8 years ago
|
majel::detail::PlacePrinter printer(os);
|
||
|
boost::apply_visitor(printer, p);
|
||
|
return os;
|
||
8 years ago
|
}
|
||
|
|
||
|
} // namespace majel
|