-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathdevice.h
More file actions
77 lines (69 loc) · 2.66 KB
/
Copy pathdevice.h
File metadata and controls
77 lines (69 loc) · 2.66 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
// vllm.cpp original (vt runtime, inventory deviation §9.1); no upstream mirror.
#pragma once
#include <cstddef>
#include <cstdint>
namespace vt {
// Queue identities are process-unique and monotonic. A native stream handle is
// not an identity by itself: CUDA's per-device default streams are all null and
// destroyed streams may later reuse the same handle value.
uint64_t NextQueueId() noexcept;
// Open device enum (.agents/backends.md): reserved entries for platforms we
// have not implemented yet keep engine-visible types backend-agnostic.
enum class DeviceType : uint8_t {
kCPU = 0,
kCUDA = 1,
kMETAL = 2,
kVULKAN = 3,
kXPU = 4,
kROCM = 5,
// Tenstorrent Blackhole (P100/P150 PCIe cards). Named after the vendor/stack
// (kROCM precedent), not the chip family: this codebase's CUDA layer already
// uses "Blackwell" (sm_120/121, GB10) pervasively, and kBLACKHOLE next to
// those would be a near-miss for both humans and grep.
// (.agents/specs/tenstorrent-backend.md, BACKEND-TENSTORRENT)
kTENSTORRENT = 6
};
constexpr size_t kNumDeviceTypes = 7;
// The canonical lowercase spelling of a device, for user-facing messages (and
// the docs that quote them). Lives here, beside the enum, rather than in the
// shared vllm layer: it names every platform EQUALLY, so it is a data list like
// the platform priority walk, not a device-specific branch — and keeping it in
// vt means adding a platform touches one enum and one switch, both in this file.
constexpr const char* DeviceTypeName(DeviceType device) {
switch (device) {
case DeviceType::kCPU:
return "cpu";
case DeviceType::kCUDA:
return "cuda";
case DeviceType::kMETAL:
return "metal";
case DeviceType::kVULKAN:
return "vulkan";
case DeviceType::kXPU:
return "xpu";
case DeviceType::kROCM:
// Upstream `vllm/platforms/rocm.py` sets `device_name = "rocm"` while its
// torch-facing `device_type` stays "cuda" (rocm.py:447-449) because ROCm
// reuses the CUDA dispatch key. We have no torch, so only the honest name
// survives here; the HIP-reuses-CUDA-spelling question does not arise.
return "rocm";
case DeviceType::kTENSTORRENT:
return "tenstorrent";
}
return "unknown";
}
struct Device {
DeviceType type = DeviceType::kCPU;
int32_t index = 0;
friend bool operator==(const Device& a, const Device& b) {
return a.type == b.type && a.index == b.index;
}
};
// Per-device execution queue (CUDA stream / Metal command queue / SYCL queue).
// CPU uses handle == nullptr. Ops never assume a global stream.
struct Queue {
Device device;
void* handle = nullptr;
uint64_t id = NextQueueId();
};
} // namespace vt