aboutsummaryrefslogtreecommitdiff
path: root/include/odp/api/spec/ml_quantize.h
blob: 25565ef27aea6d646e6188b1ae1fd02ff5440c30 (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright (c) 2023 Nokia
 */

/**
 * @file
 *
 * ODP Machine Learning (ML) quantization functions
 */

#ifndef ODP_API_SPEC_ML_QUANTIZE_H_
#define ODP_API_SPEC_ML_QUANTIZE_H_
#include <odp/visibility_begin.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <odp/api/std_types.h>

/** @addtogroup odp_ml
 *  @{
 */

/**
 * Quantize 32-bit float to uint8_t
 *
 * Quantizes 'num' 32-bit floating point values to uint8_t values using the provided scale and
 * zero point.
 *
 *   dst_u8 = (src_fp32 / scale) + zerop
 *
 * @param[out] dst_u8    Destination address for quantized values
 * @param src_fp32       Source address of values to be quantized
 * @param num            Number of values
 * @param scale          Scale for quantization
 * @param zerop          Zero point for quantization
 */
void odp_ml_fp32_to_uint8(uint8_t *dst_u8, const float *src_fp32, uint32_t num,
			  float scale, uint8_t zerop);

/**
 * De-quantize 32-bit float from uint8_t
 *
 * De-quantizes 'num' 32-bit floating point values from uint8_t values using the provided scale and
 * zero point.
 *
 *   dst_fp32 = (src_u8 - zerop) * scale
 *
 * @param[out] dst_fp32  Destination address for de-quantized values
 * @param src_u8         Source address of values to be de-quantized
 * @param num            Number of values
 * @param scale          Scale for de-quantization
 * @param zerop          Zero point for de-quantization
 */
void odp_ml_fp32_from_uint8(float *dst_fp32, const uint8_t *src_u8, uint32_t num,
			    float scale, uint8_t zerop);

/**
 * Quantize 32-bit float to int8_t
 *
 * Quantizes 'num' 32-bit floating point values to int8_t values using the provided scale and
 * zero point.
 *
 *   dst_i8 = (src_fp32 / scale) + zerop
 *
 * @param[out] dst_i8    Destination address for quantized values
 * @param src_fp32       Source address of values to be quantized
 * @param num            Number of values
 * @param scale          Scale for quantization
 * @param zerop          Zero point for quantization
 */
void odp_ml_fp32_to_int8(int8_t *dst_i8, const float *src_fp32, uint32_t num, float scale,
			 int8_t zerop);

/**
 * De-quantize 32-bit float from int8_t
 *
 * De-quantizes 'num' 32-bit floating point values from int8_t values using the provided scale and
 * zero point.
 *
 *   dst_fp32 = (src_i8 - zerop) * scale
 *
 * @param[out] dst_fp32  Destination address for de-quantized values
 * @param src_i8         Source address of values to be de-quantized
 * @param num            Number of values
 * @param scale          Scale for de-quantization
 * @param zerop          Zero point for de-quantization
 */
void odp_ml_fp32_from_int8(float *dst_fp32, const int8_t *src_i8, uint32_t num, float scale,
			   int8_t zerop);

/**
 * Quantize 32-bit float to 16-bit float
 *
 * Quantizes 'num' 32-bit floating point values to 16-bit floating point values.
 *
 * @param[out] dst_fp16  Destination address for quantized values
 * @param src_fp32       Source address of values to be quantized
 * @param num            Number of values
 */
void odp_ml_fp32_to_fp16(uint16_t *dst_fp16, const float *src_fp32, uint32_t num);

/**
 * De-quantize 32-bit float from 16-bit float
 *
 * De-quantizes 'num' 32-bit floating point values from 16-bit floating point values.
 *
 * @param[out] dst_fp32  Destination address for de-quantized values
 * @param src_fp16       Source address of values to be de-quantized
 * @param num            Number of values
 */
void odp_ml_fp32_from_fp16(float *dst_fp32, const uint16_t *src_fp16, uint32_t num);

/**
 * @}
 */

#ifdef __cplusplus
}
#endif

#include <odp/visibility_end.h>
#endif