ホーム › AI.MachineLearning.DirectML › DML_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_OPERATOR_DESC
DML_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_OPERATOR_DESC
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| ATensor | DML_TENSOR_DESC* | 8/4 | +0 | +0 | 左辺の入力を含むテンソルです。 |
| AScaleTensor | DML_TENSOR_DESC* | 8/4 | +8 | +4 | ATensor に適用するスケール係数を含むテンソルです。AScaleTensor の要素数は 1 であることが想定されます。 メモ
スケール値が 0 の場合の動作は未定義です。 |
| AZeroPointTensor | DML_TENSOR_DESC* | 8/4 | +16 | +8 | ATensor に適用するゼロ点を含むテンソルです。AZeroPointTensor の要素数は 1 であることが想定されます。AZeroPointTensor は省略可能なテンソルであり、指定しない場合は既定で 0 になります。 |
| BTensor | DML_TENSOR_DESC* | 8/4 | +24 | +12 | 右辺の入力を含むテンソルです。 |
| BScaleTensor | DML_TENSOR_DESC* | 8/4 | +32 | +16 | BTensor に適用するスケール係数を含むテンソルです。BScaleTensor の要素数は 1 であることが想定されます。 メモ
スケール値が 0 の場合の動作は未定義です。 |
| BZeroPointTensor | DML_TENSOR_DESC* | 8/4 | +40 | +20 | BTensor に適用するゼロ点を含むテンソルです。BZeroPointTensor の要素数は 1 であることが想定されます。BZeroPointTensor は省略可能なテンソルであり、指定しない場合は既定で 0 になります。 |
| OutputScaleTensor | DML_TENSOR_DESC* | 8/4 | +48 | +24 | OutputTensor に適用するスケール係数を含むテンソルです。これは、出力値を量子化する際に使用する出力量子化スケール係数を定義する入力テンソルです。OutputScaleTensor の要素数は 1 であることが想定されます。 メモ
スケール値が 0 の場合の動作は未定義です。 |
| OutputZeroPointTensor | DML_TENSOR_DESC* | 8/4 | +56 | +28 | OutputTensor に適用するゼロ点を含むテンソルです。これは、出力値を量子化する際に使用する出力量子化ゼロ点を定義する入力テンソルです。OutputZeroPointTensor の要素数は 1 であることが想定されます。OutputZeroPointTensor は省略可能なテンソルであり、指定しない場合は既定で 0 になります。 |
| OutputTensor | DML_TENSOR_DESC* | 8/4 | +64 | +32 | 結果を書き込む出力テンソルです。 |
公式ドキュメント
ATensor の各要素を BTensor の対応する要素に加算し、その結果を OutputTensor の対応する要素に格納します。ATensor と BTensor に含まれる値は次の式で逆量子化され、その後に加算されて再量子化されます。
AValue = (A - AZeroPoint) * AScale
BValue = (B - BZeroPoint) * BScale
OutputValue = AValue + BValue
// uint8 出力の場合、Min = 0、Max = 255
// int8 出力の場合、Min = -128、Max = 127
OutputTensor = clamp(round(OutputValue / OutputScale) + OutputZeroPoint, Min, Max)
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での定義
#include <windows.h>
// DML_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_OPERATOR_DESC (x64 72 / x86 36 バイト)
typedef struct DML_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_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_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_OPERATOR_DESC;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DML_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_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_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_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_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_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_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_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_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_OPERATOR_DESC struct {
ATensor uintptr
AScaleTensor uintptr
AZeroPointTensor uintptr
BTensor uintptr
BScaleTensor uintptr
BZeroPointTensor uintptr
OutputScaleTensor uintptr
OutputZeroPointTensor uintptr
OutputTensor uintptr
}type
DML_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_OPERATOR_DESC = record
ATensor: Pointer;
AScaleTensor: Pointer;
AZeroPointTensor: Pointer;
BTensor: Pointer;
BScaleTensor: Pointer;
BZeroPointTensor: Pointer;
OutputScaleTensor: Pointer;
OutputZeroPointTensor: Pointer;
OutputTensor: Pointer;
end;const DML_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_OPERATOR_DESC = extern struct {
ATensor: ?*anyopaque,
AScaleTensor: ?*anyopaque,
AZeroPointTensor: ?*anyopaque,
BTensor: ?*anyopaque,
BScaleTensor: ?*anyopaque,
BZeroPointTensor: ?*anyopaque,
OutputScaleTensor: ?*anyopaque,
OutputZeroPointTensor: ?*anyopaque,
OutputTensor: ?*anyopaque,
};type
DML_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_OPERATOR_DESC {.bycopy.} = object
ATensor: pointer
AScaleTensor: pointer
AZeroPointTensor: pointer
BTensor: pointer
BScaleTensor: pointer
BZeroPointTensor: pointer
OutputScaleTensor: pointer
OutputZeroPointTensor: pointer
OutputTensor: pointerstruct DML_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_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_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_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_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_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_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_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_ELEMENT_WISE_QUANTIZED_LINEAR_ADD_OPERATOR_DESC ; NSTRUCT 変数を確保