FreeTensor
Loading...
Searching...
No Matches
device.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_DEVICE_H
2#define FREE_TENSOR_DEVICE_H
3
4#include <iostream>
5
6#include <driver/target.h>
7#include <ref.h>
8
9namespace freetensor {
10
22class Device {
23 Ref<Target> target_;
24 int num_; // not size_t, cuda function takes ints as args
25
26 public:
27 Device(const TargetType &targetType, int num = 0);
28 Device(const TargetType &targetType, const std::string &getDeviceByName);
29 Device(const TargetType &targetType, const std::string &getDeviceByFullName,
30 size_t nth);
31
32 TargetType type() const { return target_->type(); }
33 MemType mainMemType() const { return target_->mainMemType(); }
34 int num() const { return num_; }
35 const Ref<Target> &target() const { return target_; }
36
37 void sync();
38
39 friend bool operator==(const Device &lhs, const Device &rhs) {
40 return isSameTarget(lhs.target_, rhs.target_) && lhs.num_ == rhs.num_;
41 }
42
43 friend std::ostream &operator<<(std::ostream &os, const Device &device) {
44 return os << device.target_ << ':' << device.num_;
45 }
46};
47
48} // namespace freetensor
49
50#endif // FREE_TENSOR_DEVICE_H
Definition: device.h:22
TargetType type() const
Definition: device.h:32
friend std::ostream & operator<<(std::ostream &os, const Device &device)
Definition: device.h:43
friend bool operator==(const Device &lhs, const Device &rhs)
Definition: device.h:39
int num() const
Definition: device.h:34
MemType mainMemType() const
Definition: device.h:33
const Ref< Target > & target() const
Definition: device.h:35
void sync()
Definition: device.cc:95
Definition: ref.h:24
Definition: allocator.h:9
TargetType
Definition: target_type.h:6
auto && lhs
Definition: const_fold.cc:70
bool isSameTarget(const Ref< Target > &lhs, const Ref< Target > &rhs)
Definition: target.cc:16
auto auto && rhs
Definition: const_fold.cc:70
MemType
Definition: mem_type.h:14