DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| ATensor | DML_TENSOR_DESC* | 8/4 | +0 | +0 | A のデータを格納するテンソルです。このテンソルの次元は { BatchCount, ChannelCount, M, K } でなければなりません。 |
| AScaleTensor | DML_TENSOR_DESC* | 8/4 | +8 | +4 | ATensor のスケール データを格納するテンソルです。 メモ
スケール値が 0 の場合、動作は未定義です。 |
| AZeroPointTensor | DML_TENSOR_DESC* | 8/4 | +16 | +8 | ATensor のゼロ ポイント データを格納する省略可能なテンソルです。AZeroPointTensor に期待される次元は、テンソル単位の量子化が必要な場合は { 1, 1, 1, 1 }、行単位の量子化が必要な場合は { 1, 1, M, 1 } です。これらのゼロ ポイント値は、ATensor の値を逆量子化するために使用されます。 |
| BTensor | DML_TENSOR_DESC* | 8/4 | +24 | +12 | B のデータを格納するテンソルです。このテンソルの次元は { BatchCount, ChannelCount, K, N } でなければなりません。 |
| BScaleTensor | DML_TENSOR_DESC* | 8/4 | +32 | +16 | BTensor のスケール データを格納するテンソルです。 メモ
スケール値が 0 の場合、動作は未定義です。 |
| BZeroPointTensor | DML_TENSOR_DESC* | 8/4 | +40 | +20 | BTensor のゼロ ポイント データを格納する省略可能なテンソルです。BZeroPointTensor に期待される次元は、テンソル単位の量子化が必要な場合は { 1, 1, 1, 1 }、列単位の量子化が必要な場合は { 1, 1, 1, N } です。これらのゼロ ポイント値は、BTensor の値を逆量子化するために使用されます。 |
| OutputScaleTensor | DML_TENSOR_DESC* | 8/4 | +48 | +24 | OutputTensor のスケール データを格納するテンソルです。 メモ
スケール値が 0 の場合、動作は未定義です。 |
| OutputZeroPointTensor | DML_TENSOR_DESC* | 8/4 | +56 | +28 | OutputTensor のゼロ ポイント データを格納する省略可能なテンソルです。OutputZeroPointTensor に期待される次元は、テンソル単位の量子化が必要な場合は { 1, 1, 1, 1 }、行単位の量子化が必要な場合は { 1, 1, M, 1 } です。このゼロ ポイント値は、OutputTensor の値を逆量子化するために使用されます。 |
| OutputTensor | DML_TENSOR_DESC* | 8/4 | +64 | +32 | 結果を書き込むテンソルです。このテンソルの次元は { BatchCount, ChannelCount, M, N } です。 |
公式ドキュメント
量子化されたデータに対して行列乗算関数を実行します。この演算子は、入力を逆量子化してから行列乗算を実行し、その出力を量子化する処理と数学的に等価です。
この演算子では、行列乗算の入力テンソルが { BatchCount, ChannelCount, Height, Width } の形式で表される 4D である必要があります。行列乗算演算子は、BatchCount * ChannelCount 個の独立した行列乗算を実行します。
たとえば、ATensor の Sizes が { BatchCount, ChannelCount, M, K }、BTensor の Sizes が { BatchCount, ChannelCount, K, N }、OutputTensor の Sizes が { BatchCount, ChannelCount, M, N } である場合、行列乗算演算子は次元 {M,K} x {K,N} = {M,N} の独立した行列乗算を BatchCount * ChannelCount 回実行します。
逆量子化関数
f(Input, Scale, ZeroPoint) = (Input - ZeroPoint) * Scale
量子化関数
f(Input, Scale, ZeroPoint) = clamp(round(Input / Scale) + ZeroPoint, Min, Max)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での定義
#include <windows.h>
// DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC (x64 72 / x86 36 バイト)
typedef struct DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC {
DML_TENSOR_DESC* ATensor;
DML_TENSOR_DESC* AScaleTensor;
DML_TENSOR_DESC* AZeroPointTensor;
DML_TENSOR_DESC* BTensor;
DML_TENSOR_DESC* BScaleTensor;
DML_TENSOR_DESC* BZeroPointTensor;
DML_TENSOR_DESC* OutputScaleTensor;
DML_TENSOR_DESC* OutputZeroPointTensor;
DML_TENSOR_DESC* OutputTensor;
} DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC
{
public IntPtr ATensor;
public IntPtr AScaleTensor;
public IntPtr AZeroPointTensor;
public IntPtr BTensor;
public IntPtr BScaleTensor;
public IntPtr BZeroPointTensor;
public IntPtr OutputScaleTensor;
public IntPtr OutputZeroPointTensor;
public IntPtr OutputTensor;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC
Public ATensor As IntPtr
Public AScaleTensor As IntPtr
Public AZeroPointTensor As IntPtr
Public BTensor As IntPtr
Public BScaleTensor As IntPtr
Public BZeroPointTensor As IntPtr
Public OutputScaleTensor As IntPtr
Public OutputZeroPointTensor As IntPtr
Public OutputTensor As IntPtr
End Structureimport ctypes
from ctypes import wintypes
class DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC(ctypes.Structure):
_fields_ = [
("ATensor", ctypes.c_void_p),
("AScaleTensor", ctypes.c_void_p),
("AZeroPointTensor", ctypes.c_void_p),
("BTensor", ctypes.c_void_p),
("BScaleTensor", ctypes.c_void_p),
("BZeroPointTensor", ctypes.c_void_p),
("OutputScaleTensor", ctypes.c_void_p),
("OutputZeroPointTensor", ctypes.c_void_p),
("OutputTensor", ctypes.c_void_p),
]#[repr(C)]
pub struct DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC {
pub ATensor: *mut core::ffi::c_void,
pub AScaleTensor: *mut core::ffi::c_void,
pub AZeroPointTensor: *mut core::ffi::c_void,
pub BTensor: *mut core::ffi::c_void,
pub BScaleTensor: *mut core::ffi::c_void,
pub BZeroPointTensor: *mut core::ffi::c_void,
pub OutputScaleTensor: *mut core::ffi::c_void,
pub OutputZeroPointTensor: *mut core::ffi::c_void,
pub OutputTensor: *mut core::ffi::c_void,
}import "golang.org/x/sys/windows"
type DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC struct {
ATensor uintptr
AScaleTensor uintptr
AZeroPointTensor uintptr
BTensor uintptr
BScaleTensor uintptr
BZeroPointTensor uintptr
OutputScaleTensor uintptr
OutputZeroPointTensor uintptr
OutputTensor uintptr
}type
DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC = record
ATensor: Pointer;
AScaleTensor: Pointer;
AZeroPointTensor: Pointer;
BTensor: Pointer;
BScaleTensor: Pointer;
BZeroPointTensor: Pointer;
OutputScaleTensor: Pointer;
OutputZeroPointTensor: Pointer;
OutputTensor: Pointer;
end;const DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC = extern struct {
ATensor: ?*anyopaque,
AScaleTensor: ?*anyopaque,
AZeroPointTensor: ?*anyopaque,
BTensor: ?*anyopaque,
BScaleTensor: ?*anyopaque,
BZeroPointTensor: ?*anyopaque,
OutputScaleTensor: ?*anyopaque,
OutputZeroPointTensor: ?*anyopaque,
OutputTensor: ?*anyopaque,
};type
DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC {.bycopy.} = object
ATensor: pointer
AScaleTensor: pointer
AZeroPointTensor: pointer
BTensor: pointer
BScaleTensor: pointer
BZeroPointTensor: pointer
OutputScaleTensor: pointer
OutputZeroPointTensor: pointer
OutputTensor: pointerstruct DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC
{
void* ATensor;
void* AScaleTensor;
void* AZeroPointTensor;
void* BTensor;
void* BScaleTensor;
void* BZeroPointTensor;
void* OutputScaleTensor;
void* OutputZeroPointTensor;
void* OutputTensor;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC サイズ: 36 バイト(x86)
dim st, 9 ; 4byte整数×9(構造体サイズ 36 / 4 切り上げ)
; ATensor : DML_TENSOR_DESC* (+0, 4byte) varptr(st)+0 を基点に操作(4byte:入れ子/配列)
; AScaleTensor : DML_TENSOR_DESC* (+4, 4byte) varptr(st)+4 を基点に操作(4byte:入れ子/配列)
; AZeroPointTensor : DML_TENSOR_DESC* (+8, 4byte) varptr(st)+8 を基点に操作(4byte:入れ子/配列)
; BTensor : DML_TENSOR_DESC* (+12, 4byte) varptr(st)+12 を基点に操作(4byte:入れ子/配列)
; BScaleTensor : DML_TENSOR_DESC* (+16, 4byte) varptr(st)+16 を基点に操作(4byte:入れ子/配列)
; BZeroPointTensor : DML_TENSOR_DESC* (+20, 4byte) varptr(st)+20 を基点に操作(4byte:入れ子/配列)
; OutputScaleTensor : DML_TENSOR_DESC* (+24, 4byte) varptr(st)+24 を基点に操作(4byte:入れ子/配列)
; OutputZeroPointTensor : DML_TENSOR_DESC* (+28, 4byte) varptr(st)+28 を基点に操作(4byte:入れ子/配列)
; OutputTensor : DML_TENSOR_DESC* (+32, 4byte) varptr(st)+32 を基点に操作(4byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC サイズ: 72 バイト(x64)
dim st, 18 ; 4byte整数×18(構造体サイズ 72 / 4 切り上げ)
; ATensor : DML_TENSOR_DESC* (+0, 8byte) varptr(st)+0 を基点に操作(8byte:入れ子/配列)
; AScaleTensor : DML_TENSOR_DESC* (+8, 8byte) varptr(st)+8 を基点に操作(8byte:入れ子/配列)
; AZeroPointTensor : DML_TENSOR_DESC* (+16, 8byte) varptr(st)+16 を基点に操作(8byte:入れ子/配列)
; BTensor : DML_TENSOR_DESC* (+24, 8byte) varptr(st)+24 を基点に操作(8byte:入れ子/配列)
; BScaleTensor : DML_TENSOR_DESC* (+32, 8byte) varptr(st)+32 を基点に操作(8byte:入れ子/配列)
; BZeroPointTensor : DML_TENSOR_DESC* (+40, 8byte) varptr(st)+40 を基点に操作(8byte:入れ子/配列)
; OutputScaleTensor : DML_TENSOR_DESC* (+48, 8byte) varptr(st)+48 を基点に操作(8byte:入れ子/配列)
; OutputZeroPointTensor : DML_TENSOR_DESC* (+56, 8byte) varptr(st)+56 を基点に操作(8byte:入れ子/配列)
; OutputTensor : DML_TENSOR_DESC* (+64, 8byte) varptr(st)+64 を基点に操作(8byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC
#field intptr ATensor
#field intptr AScaleTensor
#field intptr AZeroPointTensor
#field intptr BTensor
#field intptr BScaleTensor
#field intptr BZeroPointTensor
#field intptr OutputScaleTensor
#field intptr OutputZeroPointTensor
#field intptr OutputTensor
#endstruct
stdim st, DML_QUANTIZED_LINEAR_MATRIX_MULTIPLY_OPERATOR_DESC ; NSTRUCT 変数を確保