cubecl_runtime/
feature_set.rs1use crate::memory_management::{HardwareProperties, MemoryDeviceProperties};
2use alloc::collections::BTreeSet;
3
4#[derive(Debug)]
7pub struct DeviceProperties<Feature: Ord + Copy> {
8 set: alloc::collections::BTreeSet<Feature>,
9 memory: MemoryDeviceProperties,
10 hardware: HardwareProperties,
11}
12
13impl<Feature: Ord + Copy> DeviceProperties<Feature> {
14 pub fn new(
16 features: &[Feature],
17 memory_props: MemoryDeviceProperties,
18 hardware: HardwareProperties,
19 ) -> Self {
20 let mut set = BTreeSet::new();
21 for feature in features {
22 set.insert(*feature);
23 }
24
25 DeviceProperties {
26 set,
27 memory: memory_props,
28 hardware,
29 }
30 }
31
32 pub fn feature_enabled(&self, feature: Feature) -> bool {
34 self.set.contains(&feature)
35 }
36
37 pub fn register_feature(&mut self, feature: Feature) -> bool {
41 self.set.insert(feature)
42 }
43
44 pub fn memory_properties(&self) -> &MemoryDeviceProperties {
46 &self.memory
47 }
48
49 pub fn hardware_properties(&self) -> &HardwareProperties {
51 &self.hardware
52 }
53}