dynamo_llm/common/
dtype.rs

1// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4use serde::{Deserialize, Serialize};
5
6/// Represents the data type of tensor elements
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8pub enum DType {
9    FP8,
10    FP16,
11    BF16,
12    FP32,
13    U8,
14    U16,
15    U32,
16    U64,
17    I8,
18    I16,
19    I32,
20    I64,
21}
22
23impl DType {
24    /// Get the size of the data type in bytes
25    pub fn size_in_bytes(&self) -> usize {
26        match self {
27            DType::FP32 => 4,
28            DType::FP16 => 2,
29            DType::BF16 => 2,
30            DType::FP8 => 1,
31            DType::U8 => 1,
32            DType::U16 => 2,
33            DType::U32 => 4,
34            DType::U64 => 8,
35            DType::I8 => 1,
36            DType::I16 => 2,
37            DType::I32 => 4,
38            DType::I64 => 8,
39        }
40    }
41}