Skip to content

Commit 227f637

Browse files
authored
Merge pull request #131 from changy1105/gesture
fix(paddlejs-core): fix backend only one
2 parents 7665d58 + 46e8215 commit 227f637

File tree

11 files changed

+112
-23
lines changed

11 files changed

+112
-23
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PUPPETEER_SKIP_DOWNLOAD

packages/paddlejs-backend-webgl/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@paddlejs/paddlejs-backend-webgl",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "",
55
"main": "lib/index",
66
"scripts": {

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@ import WebGLBackend from './backend';
88
import { ops } from './ops';
99
import { GLHelper } from './webgl/WebGLUtils';
1010
import * as webgl_types from './webgl/webgl_types';
11+
import { GLOBALS } from '@paddlejs/paddlejs-core/globals';
1112

12-
const glInstance = new WebGLBackend();
13-
14-
function registerWebGLBackend() {
13+
let glInstance;
14+
function registerWebGLBackend(name?: string) {
15+
glInstance = new WebGLBackend();
1516
registerBackend(
16-
'webgl',
17+
name || 'webgl',
1718
glInstance,
18-
ops
19+
ops,
20+
'webgl'
1921
);
2022
return glInstance;
2123
}
2224

2325
registerWebGLBackend();
26+
GLOBALS.registerTypedBackend = registerWebGLBackend;
2427

2528
export {
2629
glInstance,

packages/paddlejs-benchmark/src/config.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export default Vue.extend({
224224
remainWholeT += t;
225225
// this.remainOthersT = +(remainWholeT / (curTimes - 2).toFixed(4));
226226
227-
const queryList = GLOBALS.backendInstance.queryList;
227+
const queryList = GLOBALS[GLOBALS.backend].backendInstance.queryList;
228228
229229
230230
if (queryList && queryList.length) {
@@ -344,4 +344,4 @@ export default Vue.extend({
344344
.el-table .detail-index-row {
345345
background-color: #f0f9eb;
346346
}
347-
</style>
347+
</style>

packages/paddlejs-core/__tests__/spec/runner.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,45 @@ describe('test runnrer', () => {
5858
expect(res).toBeUndefined();
5959
});
6060
});
61+
62+
describe('test three runnrer', () => {
63+
it('test runner init', async () => {
64+
const runner1 = new Runner({
65+
modelPath,
66+
feedShape: {
67+
fw: 5,
68+
fh: 3
69+
},
70+
fileCount: 0
71+
});
72+
73+
const runner2 = new Runner({
74+
modelPath,
75+
feedShape: {
76+
fw: 6,
77+
fh: 3
78+
},
79+
fileCount: 0
80+
});
81+
82+
const runner3 = new Runner({
83+
modelPath,
84+
feedShape: {
85+
fw: 7,
86+
fh: 3
87+
},
88+
fileCount: 0
89+
});
90+
registerBackend(
91+
'webgpu',
92+
new Backend(),
93+
ops as any
94+
);
95+
await runner1.init();
96+
expect(runner1.weightMap.length).toBe(7);
97+
await runner2.init();
98+
expect(runner2.weightMap.length).toBe(7);
99+
await runner3.init();
100+
expect(runner3.weightMap.length).toBe(7);
101+
});
102+
});

packages/paddlejs-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@paddlejs/paddlejs-core",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "",
55
"main": "lib/index",
66
"scripts": {

packages/paddlejs-core/src/globals.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ interface GLOBALS_INTERFACE {
88
opRegistry: OpRegistry;
99
backend: string;
1010
backendInstance: any; // todo Class Backend
11+
backendType: string;
12+
backendCount: number;
13+
registerTypedBackend?: Function;
1114
}
1215

1316
let GLOBALS: GLOBALS_INTERFACE = {
1417
opRegistry: {
1518
ops: {}
1619
},
1720
backend: '',
18-
backendInstance: null
21+
backendInstance: null,
22+
backendType: '',
23+
backendCount: 0
1924
};
2025

2126
function registerOp(opInfo: OpInfo, key: string) {
@@ -42,13 +47,18 @@ function registerOp(opInfo: OpInfo, key: string) {
4247
};
4348
}
4449

45-
function registerBackend(backend: string, backendInstance: any, ops: Ops) {
50+
function registerBackend(backend: string, backendInstance: any, ops: Ops, backendType?: string) {
4651
if (backend) {
4752
GLOBALS.backend = backend;
53+
GLOBALS.backendType = backendType || backend;
54+
}
55+
56+
if (!GLOBALS[GLOBALS.backend]) {
57+
GLOBALS[GLOBALS.backend] = {};
4858
}
4959

5060
if (backendInstance) {
51-
GLOBALS.backendInstance = backendInstance;
61+
GLOBALS[GLOBALS.backend].backendInstance = backendInstance;
5262
}
5363

5464
if (ops) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ export default class OpData {
146146
buildProgram() {
147147
const name = this.name;
148148
const inputTensors = this.inputTensors;
149-
this.program = this.outputTensors.map((outTensor, index) => GLOBALS.backendInstance.createProgram({
149+
const backend = GLOBALS.backend;
150+
this.program = this.outputTensors.map((outTensor, index) => GLOBALS[backend]?.backendInstance.createProgram({
150151
name,
151152
outTensor,
152153
inputTensors,
@@ -197,7 +198,7 @@ export default class OpData {
197198
data: data.data || null,
198199
isPacked: this.isPackedOp || false,
199200
binding: index,
200-
noLayout: GLOBALS.backendInstance?.noLayout
201+
noLayout: GLOBALS[GLOBALS.backend].backendInstance?.noLayout
201202
});
202203
if (tensorName === 'out') {
203204
this.outputTensors.push(tensor);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default class OpExecutor {
5858
*/
5959
execute(isRendered) {
6060
if (this.type !== 'feed') {
61-
GLOBALS.backendInstance.runProgram(this.opData, isRendered);
61+
GLOBALS[GLOBALS.backend].backendInstance.runProgram(this.opData, isRendered);
6262
}
6363

6464
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { GLOBALS } from '../globals';
1212
* @returns {Object} texture信息
1313
*/
1414
export function getTextureInfoFromTensorShape(shape: number[] = [], isPacked = false) {
15-
const GPU_TEXTURE_MAX_SIZE = GLOBALS.backendInstance.MAX_TEXTURE_SIZE || 4096;
15+
const GPU_TEXTURE_MAX_SIZE = GLOBALS[GLOBALS.backend].backendInstance.MAX_TEXTURE_SIZE || 4096;
1616
const b = shape[0];
1717
const c = shape[1];
1818
const h = shape[2];
@@ -103,7 +103,7 @@ export function formatShape(shape: number[]): number[] {
103103
* @param {Array} shape shape of tensor
104104
* @returns {number} total length of shape
105105
*/
106-
export function accShape(shape: number[]): number {
106+
export function accShape(shape: number[]): number {
107107
return shape.reduce((all, num) => all * num);
108108
}
109109

@@ -112,7 +112,7 @@ export function formatShape(shape: number[]): number[] {
112112
* @param {Array} shape shape of tensor
113113
* @returns {number} real axis after shape format to 4D
114114
*/
115-
export function formatAxis(shape: number[], axis): number {
115+
export function formatAxis(shape: number[], axis): number {
116116
const shapeLen = shape.length;
117117
const axis_temp = axis > -1 ? axis : shapeLen + axis;
118118
return 4 - shapeLen + axis_temp;

0 commit comments

Comments
 (0)