DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC結構 (directml.h)
在量化數據上執行矩陣乘法函式。 這個運算符在數學上相當於取消量化輸入,然後執行矩陣乘以,然後量化輸出。
此運算子需要矩陣乘以輸入張量為 4D,格式為 { BatchCount, ChannelCount, Height, Width }
。 矩陣乘法運算符會執行獨立矩陣乘法的 BatchCount * ChannelCount 數目。
例如,如果 ATensor大小 為 { BatchCount, ChannelCount, M, K }
,而 BTensor 的 大小 為 { BatchCount, ChannelCount, K, N }
和 OutputTensor大小{ BatchCount, ChannelCount, M, N }
,則矩陣乘法運算符會執行維度 {M,K} x {K,N} = {M,N} 的 BatchCount * ChannelCount 獨立矩陣乘法。
Dequantize 函式
f(Input, Scale, ZeroPoint) = (Input - ZeroPoint) * Scale
Quantize 函式
f(Input, Scale, ZeroPoint) = clamp(round(Input / Scale) + ZeroPoint, Min, Max)
語法
struct DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC {
const DML_TENSOR_DESC *ATensor;
const DML_TENSOR_DESC *AScaleTensor;
const DML_TENSOR_DESC *AZeroPointTensor;
const DML_TENSOR_DESC *BTensor;
const DML_TENSOR_DESC *BScaleTensor;
const DML_TENSOR_DESC *BZeroPointTensor;
const DML_TENSOR_DESC *OutputScaleTensor;
const DML_TENSOR_DESC *OutputZeroPointTensor;
const DML_TENSOR_DESC *OutputTensor;
};
成員
ATensor
類型:const DML_TENSOR_DESC*
包含 A 數據的張量。 這個張量維度應 { BatchCount, ChannelCount, M, K }
。
AScaleTensor
類型:const DML_TENSOR_DESC*
包含 ATensor 縮放數據的張量。 如果需要每個張量量化,則 AScaleTensor
的預期維度 { 1, 1, 1, 1 }
,或如果需要每個數據列量化,則 { 1, 1, M, 1 }
。 這些小數字數值用於取消量化 A 值。
注意
小數位數 0 會導致未定義的行為。
AZeroPointTensor
類型:_Maybenull_ const DML_TENSOR_DESC*
選擇性張量,其中包含 ATensor 零點數據。 如果需要每個 tensor 仲裁,則 AZeroPointTensor 的預期維度會 { 1, 1, 1, 1 }
,或者如果需要每個數據列量化,則 { 1, 1, M, 1 }
。 這些零點值用於取消量化 ATensor 值。
BTensor
類型:const DML_TENSOR_DESC*
包含 B 數據的張量。 這個張量維度應 { BatchCount, ChannelCount, K, N }
。
BScaleTensor
類型:const DML_TENSOR_DESC*
包含 BTensor 縮放數據的張量。 如果需要每個張量量化,則 BScaleTensor
的預期維度 { 1, 1, 1, 1 }
,或如果需要每個數據行量化,則 { 1, 1, 1, N }
。 這些小數字數值用於取消量化 BTensor 值。
注意
小數位數 0 會導致未定義的行為。
BZeroPointTensor
類型:_Maybenull_ const DML_TENSOR_DESC*
選擇性的張量,其中包含 BTensor 零點數據。 如果需要每個張量量化,則 BZeroPointTensor
的預期維度 { 1, 1, 1, 1 }
,或如果需要每個數據行量化,則 { 1, 1, 1, N }
。 這些零點值用於取消量化 BTensor 值。
OutputScaleTensor
類型:const DML_TENSOR_DESC*
包含 OutputTensor 縮放數據的張量。 如果需要每張量量化,則 OutputScaleTensor
的預期維度會 { 1, 1, 1, 1 }
,如果需要每個數據列的量化,則為 { 1, 1, M, 1 }
。 此小數字數值用於將 outputTensor 值取消量化
注意
小數位數 0 會導致未定義的行為。
OutputZeroPointTensor
類型:_Maybenull_ const DML_TENSOR_DESC*
選擇性張量,其中包含 OutputTensor 零點數據。 如果需要每張量量化,則 OutputZeroPointTensor
的預期維度會 { 1, 1, 1, 1 }
,如果需要每個數據列的量化,則為 { 1, 1, M, 1 }
。 這個零點值用於取消量化 outputTensor 值。
OutputTensor
類型:const DML_TENSOR_DESC*
要寫入結果的張量。 這個張量維度 { BatchCount, ChannelCount, M, N }
。
可用性
此運算子是在 DML_FEATURE_LEVEL_2_1
中引進的。
Tensor 條件約束
- AScaleTensor、AZeroPointTensor、BScaleTensor、BZeroPointTensor、OutputScaleTensor和 OutputZeroPointTensor 必須具有相同 DimensionCount。
- ATensor、BTensor和 OutputTensor 必須具有相同的 DimensionCount 。
- BTensor 和 BZeroPointTensor 必須具有相同 的 DataType。
- OutputTensor 和 OutputZeroPointTensor 必須具有相同的 DataType 。
- AScaleTensor、AZeroPointTensor、BScaleTensor、BZeroPointTensor、OutputScaleTensor和 OutputZeroPointTensor 必須具有相同 DimensionCount。
- ATensor 和 AZeroPointTensor 必須具有相同 的 DataType。
Tensor 支援
DML_FEATURE_LEVEL_4_0和更新版本
張肌 | 類 | 支援的維度計數 | 支援的數據類型 |
---|---|---|---|
ATensor | 輸入 | 2 到 4 | INT8、UINT8 |
AScaleTensor | 輸入 | 1 到 4 | FLOAT32 |
AZeroPointTensor | 選擇性輸入 | 1 到 4 | INT8、UINT8 |
BTensor | 輸入 | 2 到 4 | INT8、UINT8 |
BScaleTensor | 輸入 | 1 到 4 | FLOAT32 |
BZeroPointTensor | 選擇性輸入 | 1 到 4 | INT8、UINT8 |
OutputScaleTensor | 輸入 | 1 到 4 | FLOAT32 |
OutputZeroPointTensor | 選擇性輸入 | 1 到 4 | INT8、UINT8 |
OutputTensor | 輸出 | 2 到 4 | INT8、UINT8 |
DML_FEATURE_LEVEL_2_1和更新版本
張肌 | 類 | 支援的維度計數 | 支援的數據類型 |
---|---|---|---|
ATensor | 輸入 | 4 | INT8、UINT8 |
AScaleTensor | 輸入 | 4 | FLOAT32 |
AZeroPointTensor | 選擇性輸入 | 4 | INT8、UINT8 |
BTensor | 輸入 | 4 | INT8、UINT8 |
BScaleTensor | 輸入 | 4 | FLOAT32 |
BZeroPointTensor | 選擇性輸入 | 4 | INT8、UINT8 |
OutputScaleTensor | 輸入 | 4 | FLOAT32 |
OutputZeroPointTensor | 選擇性輸入 | 4 | INT8、UINT8 |
OutputTensor | 輸出 | 4 | INT8、UINT8 |
要求
要求 | 價值 |
---|---|
最低支援的用戶端 | Windows 10 組建 20348 |
支援的最低伺服器 | Windows 10 組建 20348 |
標頭 | directml.h |