Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/paddlejs-backend-webgl/src/ops/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ const ops = {
pack_out,
nhwc_2_nchw,
feedPost,
imgFeed
imgFeed,
'conv2d-elementwise_add-leaky_relu': conv2d_elementwise_add
};
export {
ops
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
* @file greater_than return x >= y
*/

function mainFunc(
{},
{}
) {
function mainFunc() {
return `
// start函数
void main(void) {
ivec4 oPos = getOutputTensorPos();
// 输出坐标转换为输入坐标
float x = getValueFromTensorPos_input(oPos.r, oPos.g, oPos.b, oPos.a);
float x = getValueFromTensorPos_origin(oPos.r, oPos.g, oPos.b, oPos.a);
float y = getValueFromTensorPos_counter(oPos.r, oPos.g, oPos.b, oPos.a);

setOutput(bool(x >= y));
setOutput(float(bool(x >= y)));
}
`;
}
Expand Down
28 changes: 20 additions & 8 deletions packages/paddlejs-backend-webgl/src/ops/shader/reduce_mean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,32 @@
*/

function mainFunc(
{},
{ inputs_dim, dim }
{ origin },
{ dim }
) {
const { total_shape, height_shape, width_shape, channel } = origin;
const batch_shape = total_shape / (width_shape * height_shape * channel);
const shape = [batch_shape, channel, height_shape, width_shape];
let codeStr = '';
for (let i = 0; i < dim.length; i++) {
for (let j = 0; j < shape[dim[i]]; j++) {
codeStr += `
oPos[${dim[i]}] = ${j};
o += getValueFromTensorPos_origin(oPos.r, oPos.g, oPos.b, oPos.a);
`;
if (j === shape[dim[i]]) {
codeStr += `o / float(${j});`;
}
}
}

return `
// start函数
void main(void) {
ivec4 oPos = getOutputTensorPos();
// 输出坐标转换为输入坐标
float o = 0.0;
for (int i = 0; i < ${inputs_dim}; i++) {
oPos[${dim}] = i;
o += getValueFromTensorPos_origin(oPos.r, oPos.g, oPos.b, oPos.a);
}
o = o / float(${inputs_dim});
${codeStr}
setOutput(o);
}
`;
Expand All @@ -32,6 +44,6 @@ export default {
origin: ['getValueFromTensorPos']
},
behaviors: [
'normalizeDim'

]
};
26 changes: 17 additions & 9 deletions packages/paddlejs-backend-webgl/src/ops/shader/reduce_sum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@
*/

function mainFunc(
{},
{ inputs_dim, dim }
{ origin },
{ dim }
) {
const { total_shape, height_shape, width_shape, channel } = origin;
const batch_shape = total_shape / (width_shape * height_shape * channel);
const shape = [batch_shape, channel, height_shape, width_shape];
let codeStr = '';
for (let i = 0; i < dim.length; i++) {
for (let j = 0; j < shape[dim[i]]; j++) {
codeStr += `
oPos[${dim[i]}] = ${j};
o += getValueFromTensorPos_origin(oPos.r, oPos.g, oPos.b, oPos.a);
`;
}
}

return `
// start函数
void main(void) {
ivec4 oPos = getOutputTensorPos();
// 输出坐标转换为输入坐标
float o = 0.0;
for (int i = 0; i < ${inputs_dim}; i++) {
oPos[${dim}] = i;
o += getValueFromTensorPos_origin(oPos.r, oPos.g, oPos.b, oPos.a);;
}
${codeStr}
setOutput(float(o));
}
`;
Expand All @@ -30,7 +40,5 @@ export default {
textureFuncConf: {
origin: ['getValueFromTensorPos']
},
behaviors: [
'normalizeDim'
]
behaviors: []
};
7 changes: 2 additions & 5 deletions packages/paddlejs-backend-webgl/src/ops/shader/where.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
* @file where return condition ? x : y
*/

function mainFunc(
{},
{}
) {
function mainFunc() {
return `
// start函数
void main(void) {
ivec4 oPos = getOutputTensorPos();
// 输出坐标转换为输入坐标
float x = getValueFromTensorPos_input(oPos.r, oPos.g, oPos.b, oPos.a);
float x = getValueFromTensorPos_origin(oPos.r, oPos.g, oPos.b, oPos.a);
float y = getValueFromTensorPos_counter(oPos.r, oPos.g, oPos.b, oPos.a);
float condition = getValueFromTensorPos_condition(oPos.r, oPos.g, oPos.b, oPos.a);
float o = 0.0;
Expand Down
14 changes: 12 additions & 2 deletions packages/paddlejs-core/src/opFactory/opDataBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,24 @@ export default class OpData {
this.name = 'conv2d_elementwise_add';
}

if (this.name.indexOf('flatten2') > -1) {
else if (this.name.indexOf('flatten2') > -1) {
this.name = 'reshape2';
}

if (this.name.indexOf('max_pool2d_with_index') > -1) {
else if (this.name.indexOf('max_pool2d_with_index') > -1) {
this.name = 'pool2d_max';
}

else if (this.name.indexOf('instance_norm') > -1 || this.name.indexOf('sync_batch_norm') > -1) {
this.name = 'batchnorm';
}
else if (this.name.indexOf('bilinear_interp_v2') > -1) {
this.name = 'bilinear_interp';
}
else if (this.name.indexOf('leaky_relu') > -1) {
this.name = 'conv2d_elementwise_add';
}

const tensorData: ModelVar[] = this.tensorData;
// unique behavior
const opKey = `${GLOBALS.backend}_${this.name}`;
Expand Down