forked from plaidml/plaidml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device_state.h
64 lines (50 loc) · 1.78 KB
/
device_state.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2017-2018 Intel Corporation.
#pragma once
#include <memory>
#include "base/context/context.h"
#include "tile/hal/opencl/ocl.h"
#include "tile/hal/opencl/opencl.pb.h"
#include "tile/lang/generate.h"
namespace vertexai {
namespace tile {
namespace hal {
namespace opencl {
// DeviceState represents the state of a device, including all OpenCL objects needed to control the device.
class DeviceState {
public:
struct Queue {
CLObj<cl_command_queue> cl_queue;
cl_command_queue_properties props;
void Flush() const;
};
DeviceState(const context::Context& ctx, const CLObj<cl_context>& cl_ctx, cl_device_id did, proto::DeviceInfo info);
void Initialize(const hal::proto::HardwareSettings& settings);
const cl_device_id did() const { return did_; }
const CLObj<cl_context>& cl_ctx() const { return cl_ctx_; }
const proto::DeviceInfo& info() const { return info_; }
const Queue& cl_normal_queue() const { return *cl_normal_queue_; }
const Queue& cl_profiling_queue() const { return *cl_profiling_queue_; }
const Queue& cl_queue(bool enable_profiling) const {
if (enable_profiling) {
return cl_profiling_queue();
}
return cl_normal_queue();
}
const context::Clock& clock() const { return clock_; }
const context::proto::ActivityID& id() const { return id_; }
cl_map_flags map_discard_flags() const;
void FlushCommandQueue();
bool HasDeviceExtension(const char* extension);
private:
const cl_device_id did_;
const proto::DeviceInfo info_;
const CLObj<cl_context> cl_ctx_;
std::unique_ptr<const Queue> cl_normal_queue_;
std::unique_ptr<const Queue> cl_profiling_queue_;
const context::Clock clock_;
const context::proto::ActivityID id_;
};
} // namespace opencl
} // namespace hal
} // namespace tile
} // namespace vertexai