Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
;++
;
; Copyright (c) Microsoft Corporation. All rights reserved.
;
; Licensed under the MIT License.
;
; Module Name:
;
;   SpoolKernelAvx.asm
;
; Abstract:
;
;   This module implements the kernels for the single precision pooling
;   operation.
;
;   This implementation uses AVX instructions.
;
;--
 
        .xlist
INCLUDE mlasi.inc
INCLUDE SpoolKernelAvxCommon.inc
        .list
 
;
; Macro Description:
;
;   This macro generates code to initialize registers used across the kernel.
;
; Arguments:
;
;   PoolingType - Supplies the pooling type string.
;
 
InitializeKernel MACRO PoolingType
 
IFIDNI <PoolingType>, <Maximum>
        mov     DWORD PTR SpoolKernelFrame.PreviousP1Home[rsp],0FF7FFFFFh
        vbroadcastss ymm5,DWORD PTR SpoolKernelFrame.PreviousP1Home[rsp]
ELSE
        vxorps  xmm5,xmm5,xmm5              ; initialize default divisor vector
IFIDNI <PoolingType>, <AverageExcludePad>
        mov     rax,SpoolKernelFrame.KernelHeight[rsp]
        imul    rax,SpoolKernelFrame.KernelWidth[rsp]
        vcvtsi2ss xmm5,xmm5,rax
ELSE
        vcvtsi2ss xmm5,xmm5,SpoolKernelFrame.ActualKernelSize[rsp]
ENDIF
        vshufps xmm5,xmm5,xmm5,0
        vinsertf128 ymm5,ymm5,xmm5,1        ; AVX lacks "vbroadcastss ymm5,xmm5"
ENDIF
 
        ENDM
 
;
; Macro Description:
;
;   This macro generates code to clear the pooling intermediates.
;
;   For PoolingType==Maximum, the pooling intermediates are set to the minimum
;   float value. Otherwise, the pooling intermediates are cleared to zero.
;
; Arguments:
;
;   PoolingType - Supplies the pooling type string.
;
;   OutputCount - Supplies the number of output blocks to produce.
;
; Implicit Arguments:
;
;   rsi - Supplies the number of blocks accessed by ComputeBlock, if
;       PoolingType=AverageExcludePad and OutputCount=1.
;
;   ymm0-ymm2 - Supplies the pooling intermediates.
;
;   ymm5 - Supplies a vector containing the minimum float value broadcasted,
;       if PoolingType==Maximum.
;
 
ClearBlock MACRO PoolingType, OutputCount
 
IFIDNI <PoolingType>, <Maximum>
        EmitIfCountGE OutputCount, 1, <vmovaps ymm0,ymm5>
        EmitIfCountGE OutputCount, 2, <vmovaps ymm1,ymm5>
        EmitIfCountGE OutputCount, 3, <vmovaps ymm2,ymm5>
ELSE
        EmitIfCountGE OutputCount, 1, <vxorps xmm0,xmm0,xmm0>
        EmitIfCountGE OutputCount, 2, <vxorps xmm1,xmm1,xmm1>
        EmitIfCountGE OutputCount, 3, <vxorps xmm2,xmm2,xmm2>
ENDIF
 
IFIDNI <PoolingType>, <AverageExcludePad>
IF OutputCount EQ 1
        xor     rsi,rsi                     ; reset valid block counter
ENDIF
ENDIF
 
        ENDM
 
;
; Macro Description:
;
;   This macro generates code to sample the input buffer and update the pooling
;   intermediates as appropriate.
;
; Arguments:
;
;   PoolingType - Supplies the pooling type string.
;
;   OutputCount - Supplies the number of output blocks to produce.
;
; Implicit Arguments:
;
;   rcx - Supplies the address of the input buffer.
;
;   rsi - Supplies the number of blocks accessed by ComputeBlock, if
;       PoolingType=AverageExcludePad and OutputCount=1.
;
;   r8 - Supplies the StrideWidth parameter (see function description).
;
;   ymm0-ymm2 - Supplies the pooling intermediates.
;
 
ComputeBlock MACRO PoolingType, OutputCount
 
IFIDNI <PoolingType>, <Maximum>
        EmitIfCountGE OutputCount, 1, <vmaxps ymm0,ymm0,YMMWORD PTR [rcx]>
        EmitIfCountGE OutputCount, 2, <vmaxps ymm1,ymm1,YMMWORD PTR [rcx+r8]>
        EmitIfCountGE OutputCount, 3, <vmaxps ymm2,ymm2,YMMWORD PTR [rcx+r8*2]>
ELSE
        EmitIfCountGE OutputCount, 1, <vaddps ymm0,ymm0,YMMWORD PTR [rcx]>
        EmitIfCountGE OutputCount, 2, <vaddps ymm1,ymm1,YMMWORD PTR [rcx+r8]>
        EmitIfCountGE OutputCount, 3, <vaddps ymm2,ymm2,YMMWORD PTR [rcx+r8*2]>
ENDIF
 
IFIDNI <PoolingType>, <AverageExcludePad>
IF OutputCount EQ 1
        inc     rsi                         ; increment valid block counter
ENDIF
ENDIF
 
        ENDM
 
;
; Macro Description:
;
;   This macro generates code to process and store the pooling intermediates.
;
; Arguments:
;
;   PoolingType - Supplies the pooling type string.
;
;   OutputCount - Supplies the number of output blocks to produce.
;
; Implicit Arguments:
;
;   rdx - Supplies the address of the output buffer.
;
;   rsi - Supplies the number of blocks accessed by ComputeBlock, if
;       PoolingType=AverageExcludePad and OutputCount=1.
;
;   ymm0-ymm2 - Supplies the pooling intermediates.
;
;   ymm5 - Supplies the kernel size computed by InitializeKernel, if
;       PoolingType=AverageExcludePad, else the actual kernel size, if
;       PoolingType=AverageIncludePad.
;
 
PostProcessBlock MACRO PoolingType, OutputCount
 
;
; If PoolingType=AverageExcludePad, divide the sum by the number of non-padding
; blocks. OutputCount=1 generates code to count the number of blocks accessed by
; ComputeBlock. Other cases use the kernel size computed by InitializeKernel.
;
 
IFIDNI <PoolingType>, <AverageExcludePad>
IF OutputCount EQ 1
        vxorps  xmm4,xmm4,xmm4
        vcvtsi2ss xmm4,xmm4,rsi             ; convert valid block counter
        vshufps xmm4,xmm4,xmm4,0
        vinsertf128 ymm4,ymm4,xmm4,1        ; AVX lacks "vbroadcastss ymm4,xmm4"
        vdivps  ymm0,ymm0,ymm4
ELSE
        EmitIfCountGE OutputCount, 1, <vdivps ymm0,ymm0,ymm5>
        EmitIfCountGE OutputCount, 2, <vdivps ymm1,ymm1,ymm5>
        EmitIfCountGE OutputCount, 3, <vdivps ymm2,ymm2,ymm5>
ENDIF
ENDIF
 
;
; If PoolingType=AverageIncludePad, divide the sum by the actual kernel size.
;
 
IFIDNI <PoolingType>, <AverageIncludePad>
        EmitIfCountGE OutputCount, 1, <vdivps ymm0,ymm0,ymm5>
        EmitIfCountGE OutputCount, 2, <vdivps ymm1,ymm1,ymm5>
        EmitIfCountGE OutputCount, 3, <vdivps ymm2,ymm2,ymm5>
ENDIF
 
;
; Store the output block in the output buffer.
;
 
        EmitIfCountGE OutputCount, 1, <vmovups YMMWORD PTR [rdx],ymm0>
        EmitIfCountGE OutputCount, 2, <vmovups YMMWORD PTR [rdx+8*4],ymm1>
        EmitIfCountGE OutputCount, 3, <vmovups YMMWORD PTR [rdx+16*4],ymm2>
        add     rdx,OutputCount*8*4         ; advance output by N nchw8c blocks
 
        ENDM
 
;
; Generate the pooling kernels.
;
 
SpoolKernelFunction Maximum, Avx
SpoolKernelFunction AverageExcludePad, Avx
SpoolKernelFunction AverageIncludePad, Avx
 
        END