forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vulkan] adaptive_avg_pool2d (pytorch#41220)
Summary: Pull Request resolved: pytorch#41220 Test Plan: Imported from OSS Reviewed By: AshkanAliabadi Differential Revision: D22754943 Pulled By: IvanKobzarev fbshipit-source-id: 91a94f32db005ebb693384f4d27efe66e2c33a14
- Loading branch information
1 parent
0a09601
commit 4f72382
Showing
7 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#version 450 core | ||
layout(std430) buffer; | ||
layout(std430) uniform; | ||
layout(set = 0, rgba16f, binding = 0) writeonly highp uniform image3D uOutput; | ||
layout(set = 0, binding = 1) uniform highp sampler3D uInput; | ||
layout(set = 0, binding = 2) uniform constBlock { | ||
int IW; | ||
int IH; | ||
int OW; | ||
int OH; | ||
} | ||
uConstBlock; | ||
|
||
layout(local_size_x_id = 1, local_size_y_id = 2, local_size_z_id = 3) in; | ||
|
||
void main() { | ||
ivec3 pos = ivec3(gl_GlobalInvocationID); | ||
int ow = uConstBlock.OW; | ||
int oh = uConstBlock.OH; | ||
if (pos.x < ow && pos.y < oh) { | ||
int iw = uConstBlock.IW; | ||
int ih = uConstBlock.IH; | ||
|
||
int sx = int(floor(float(pos.x * iw) / ow)); | ||
int sy = int(floor(float(pos.y * ih) / oh)); | ||
int ex = int(ceil(float((pos.x + 1) * iw) / ow)); | ||
int ey = int(ceil(float((pos.y + 1) * ih) / oh)); | ||
|
||
vec4 r = vec4(1.0) / float(ex - sx) / float(ey - sy); | ||
vec4 acc = vec4(0); | ||
|
||
int xi, yi; | ||
for (xi = sx; xi < ex; ++xi) { | ||
for (yi = sy; yi < ey; ++yi) { | ||
acc += texelFetch(uInput, ivec3(xi, yi, pos.z), 0); | ||
} | ||
} | ||
|
||
imageStore(uOutput, pos, r * acc); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters