Skip to content

Commit 55598db

Browse files
Merge pull request #194 from JingyuanZhang/master
feat(webgl): change packing op name when transforms and del redundant…
2 parents 9b2cb08 + 503faba commit 55598db

File tree

6 files changed

+32
-16
lines changed

6 files changed

+32
-16
lines changed

packages/paddlejs-backend-webgl/src/backend.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ export default class WebGLBackend extends PaddlejsBackend {
9696

9797

9898

99-
createProgram({ name, outTensor, inputTensors, shaderParams, runtime, isFinalOp, isPacked }) {
99+
createProgram({ name, outTensor, inputTensors, shaderParams, runtime, isFinalOp }) {
100100
// genFscode buildShader
101-
const fsCode = buildShader(this.textureConf, name, inputTensors, shaderParams, runtime, isPacked);
101+
const fsCode = buildShader(this.textureConf, name, inputTensors, shaderParams, runtime);
102102

103103
const programInstance = new GLProgram(this.gl, this.vShader as WebGLShader, fsCode, outTensor);
104104
programInstance.fsCode = fsCode;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @file feed post process
3+
*/
4+
5+
function mainFunc(
6+
{},
7+
{}
8+
) {
9+
10+
return `
11+
// start函数
12+
void main(void) {
13+
ivec4 oPos = getOutputTensorPos();
14+
vec4 o = getValueFromTensorPosPacking_origin(oPos.r, oPos.g, oPos.b, oPos.a);
15+
setPackedOutput(o / 255.0);
16+
}
17+
`;
18+
}
19+
export default {
20+
mainFunc,
21+
params: [],
22+
textureFuncConf: {
23+
origin: ['getValueFromTensorPosPacking']
24+
}
25+
};

packages/paddlejs-backend-webgl/src/ops/utils.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,6 @@ function getTensorParams(inputTensors: Tensor[], ownParams: [], fShaderParams: o
103103
return { textureParams: tensorsParams, opParams, active_function: fShaderParams['active_function'] };
104104
}
105105

106-
107-
function getExactOpName(name, isPacked) {
108-
if (name.indexOf('conv2d-elementwise_add') > -1) {
109-
return 'conv2d_elementwise_add';
110-
}
111-
return isPacked ? `${name}_packing` : name;
112-
}
113-
114106
export {
115-
getExactOpName,
116107
getTensorParams
117108
};

packages/paddlejs-backend-webgl/src/webgl/buildShader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
import { env } from '@paddlejs/paddlejs-core';
77
import { ops } from '../ops';
8-
import { getTensorParams, getExactOpName } from '../ops/utils';
8+
import { getTensorParams } from '../ops/utils';
99
import genPrefixCode from '../ops/atom/prefix';
1010
import genSuffixCode from '../ops/atom/suffix';
1111
import * as commonFunc from '../ops/atom/common_func';
1212
import * as textureFunc from '../ops/atom/common_func_with_texture';
1313

14-
export default function buildShader(textureConf, type, inputTensors, fShaderParams, runtime: number, isPacked = false) {
14+
export default function buildShader(textureConf, type, inputTensors, fShaderParams, runtime: number) {
1515
let code = '';
16-
const opName = getExactOpName(type, isPacked);
16+
const opName = type;
1717
try {
1818

1919
const { params = {}, mainFunc, textureFuncConf = {}, commonFuncConf } = ops[opName];

packages/paddlejs-core/src/opFactory/opDataBuilder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ export default class OpData {
154154
outTensor,
155155
inputTensors,
156156
shaderParams: this.fShaderParams[index],
157-
runtime: index,
158-
isPacked: this.isPackedOp || false
157+
runtime: index
159158
}));
160159
}
161160

packages/paddlejs-core/src/transform/texturePacking.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ function transformOriginOp(op, opsMap) {
100100
.forEach(key => {
101101
op.outputs[key] = [`${op.outputs[key]}_packed`];
102102
});
103+
op.type = `${op.type}_packing`;
103104
op.id = `${op.type}_${+new Date()}_${opsMap.length}`;
104105
op.isPacked = true;
105106
}

0 commit comments

Comments
 (0)