MLX
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1// Copyright © 2023-2024 Apple Inc.
2
3#pragma once
4
5#include <Accelerate/Accelerate.h>
6#include "mlx/dtype.h"
7
8namespace mlx::core {
9
10BNNSDataType to_bnns_dtype(Dtype mlx_dtype) {
11 uint32_t size_bits = size_of(mlx_dtype) * 8;
12 switch (kindof(mlx_dtype)) {
13 case Dtype::Kind::b:
14 return BNNSDataTypeBoolean;
15 case Dtype::Kind::u:
16 return BNNSDataType(BNNSDataTypeUIntBit | size_bits);
17 case Dtype::Kind::i:
18 return BNNSDataType(BNNSDataTypeIntBit | size_bits);
19 case Dtype::Kind::f:
20 return BNNSDataType(BNNSDataTypeFloatBit | size_bits);
21 case Dtype::Kind::V:
22 return BNNSDataTypeBFloat16;
23 case Dtype::Kind::c:
24 throw std::invalid_argument("BNNS does not support complex types");
25 }
26}
27
28} // namespace mlx::core
Definition allocator.h:7
BNNSDataType to_bnns_dtype(Dtype mlx_dtype)
Definition utils.h:10
Dtype::Kind kindof(const Dtype &t)
uint8_t size_of(const Dtype &t)
Definition dtype.h:93
Definition dtype.h:13