Skip to content

Commit b98317b

Browse files
authored
[js/webgpu] following up for JSEP/WebGPU code cleanup (#15666)
### Description This PR resolves a part of non-critical comments from code review comments in #14579. - use `USE_JSEP` instead of `USE_JS` in build definition to make it less ambiguous - remove unused util functions from util.ts - fix transpose.h - other misc fixes
1 parent ebaafac commit b98317b

File tree

16 files changed

+35
-351
lines changed

16 files changed

+35
-351
lines changed

cmake/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ option(onnxruntime_USE_QNN "Build with QNN support" OFF)
6868
option(onnxruntime_USE_SNPE "Build with SNPE support" OFF)
6969
option(onnxruntime_USE_RKNPU "Build with RKNPU support" OFF)
7070
option(onnxruntime_USE_DNNL "Build with DNNL support" OFF)
71-
option(onnxruntime_USE_JS "Build with JavaScript implemented kernels support" OFF)
71+
option(onnxruntime_USE_JSEP "Build with JavaScript implemented kernels support" OFF)
7272
option(onnxruntime_BUILD_UNIT_TESTS "Build ONNXRuntime unit tests" ON)
7373
option(onnxruntime_BUILD_CSHARP "Build C# library" OFF)
7474
option(onnxruntime_BUILD_OBJC "Build Objective-C library" OFF)
@@ -662,9 +662,9 @@ if (onnxruntime_USE_NNAPI_BUILTIN)
662662
list(APPEND ORT_PROVIDER_CMAKE_FLAGS -Donnxruntime_USE_NNAPI_BUILTIN=1)
663663
list(APPEND ONNXRUNTIME_PROVIDER_NAMES nnapi)
664664
endif()
665-
if (onnxruntime_USE_JS)
666-
list(APPEND ORT_PROVIDER_FLAGS -DUSE_JS=1)
667-
list(APPEND ORT_PROVIDER_CMAKE_FLAGS -Donnxruntime_USE_JS=1)
665+
if (onnxruntime_USE_JSEP)
666+
list(APPEND ORT_PROVIDER_FLAGS -DUSE_JSEP=1)
667+
list(APPEND ORT_PROVIDER_CMAKE_FLAGS -Donnxruntime_USE_JSEP=1)
668668
list(APPEND ONNXRUNTIME_PROVIDER_NAMES js)
669669
endif()
670670
if (onnxruntime_USE_QNN)

cmake/onnxruntime_providers.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ endif()
114114
if(onnxruntime_USE_NNAPI_BUILTIN)
115115
set(PROVIDERS_NNAPI onnxruntime_providers_nnapi)
116116
endif()
117-
if(onnxruntime_USE_JS)
117+
if(onnxruntime_USE_JSEP)
118118
set(PROVIDERS_JS onnxruntime_providers_js)
119119
endif()
120120
if(onnxruntime_USE_QNN)
@@ -1067,8 +1067,8 @@ if (onnxruntime_USE_NNAPI_BUILTIN)
10671067
endif()
10681068
endif()
10691069

1070-
if (onnxruntime_USE_JS)
1071-
add_compile_definitions(USE_JS=1)
1070+
if (onnxruntime_USE_JSEP)
1071+
add_compile_definitions(USE_JSEP=1)
10721072

10731073
file(GLOB_RECURSE onnxruntime_providers_js_cc_srcs
10741074
"${ONNXRUNTIME_ROOT}/core/providers/js/*.h"

cmake/onnxruntime_unittests.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ if(onnxruntime_USE_NNAPI_BUILTIN)
504504
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_nnapi)
505505
endif()
506506

507-
if(onnxruntime_USE_JS)
507+
if(onnxruntime_USE_JSEP)
508508
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_js)
509509
endif()
510510

@@ -609,7 +609,7 @@ if(onnxruntime_USE_NNAPI_BUILTIN)
609609
list(APPEND onnxruntime_test_providers_libs onnxruntime_providers_nnapi)
610610
endif()
611611

612-
if(onnxruntime_USE_JS)
612+
if(onnxruntime_USE_JSEP)
613613
list(APPEND onnxruntime_test_framework_src_patterns ${TEST_SRC_DIR}/providers/js/*)
614614
list(APPEND onnxruntime_test_framework_libs onnxruntime_providers_js)
615615
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_js)
@@ -851,7 +851,7 @@ if (onnxruntime_BUILD_WEBASSEMBLY)
851851
if (onnxruntime_ENABLE_WEBASSEMBLY_THREADS)
852852
set_property(TARGET onnxruntime_test_all APPEND_STRING PROPERTY LINK_FLAGS " -s USE_PTHREADS=1 -s PROXY_TO_PTHREAD=1")
853853
endif()
854-
if (onnxruntime_USE_JS)
854+
if (onnxruntime_USE_JSEP)
855855
set_property(TARGET onnxruntime_test_all APPEND_STRING PROPERTY LINK_FLAGS " --pre-js \"${ONNXRUNTIME_ROOT}/wasm/js_internal_api.js\"")
856856
endif()
857857
endif()

cmake/onnxruntime_webassembly.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ else()
199199
endif()
200200

201201
set(EXPORTED_RUNTIME_METHODS "['stackAlloc','stackRestore','stackSave','UTF8ToString','stringToUTF8','lengthBytesUTF8']")
202-
if (onnxruntime_USE_JS)
202+
if (onnxruntime_USE_JSEP)
203203
set(EXPORTED_FUNCTIONS "_malloc,_free,_JsepOutput")
204204
else()
205205
set(EXPORTED_FUNCTIONS "_malloc,_free")
@@ -219,12 +219,12 @@ else()
219219
--no-entry
220220
)
221221

222-
if (onnxruntime_USE_JS)
222+
if (onnxruntime_USE_JSEP)
223223
# NOTE: "-s ASYNCIFY=1" is required for JSEP to work with WebGPU
224224
# This flag allows async functions to be called from sync functions, in the cost of binary size and
225225
# build time. See https://emscripten.org/docs/porting/asyncify.html for more details.
226226

227-
target_compile_definitions(onnxruntime_webassembly PRIVATE USE_JS=1)
227+
target_compile_definitions(onnxruntime_webassembly PRIVATE USE_JSEP=1)
228228
target_link_options(onnxruntime_webassembly PRIVATE
229229
--pre-js "${ONNXRUNTIME_ROOT}/wasm/js_internal_api.js"
230230
"SHELL:-s ASYNCIFY=1"

js/web/lib/wasm/jsep/backend-webgpu.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ export class WebGpuBackend {
144144
}
145145

146146
dispose(): void {
147-
// TODO: uninitialization
148-
// this.glContext.dispose();
147+
// currently, we do not do anything in this function. In all known use cases, we don't have the requirement to
148+
// actually dispose the WebGpuBackend instance, because it's always used as a singleton.
149+
//
150+
// revisit this place if we get real requirement to dispose the instance.
149151
}
150152

151153
getCommandEncoder(): GPUCommandEncoder {

js/web/lib/wasm/jsep/init.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TensorViewImpl implements TensorView {
2929
}
3030
}
3131

32-
class OpKernelContext implements ComputeContext {
32+
class ComputeContextImpl implements ComputeContext {
3333
readonly opKernelContext: number;
3434
readonly inputs: readonly TensorView[];
3535
get customData(): {[key: string]: unknown} {
@@ -142,7 +142,7 @@ export const init = async(module: OrtWasmModule): Promise<void> => {
142142
// jsepRun
143143
(kernel: number, contextDataOffset: number) => {
144144
LOG_DEBUG('verbose', () => `[WebGPU] jsepRun: kernel=${kernel}, contextDataOffset=${contextDataOffset}`);
145-
const context = new OpKernelContext(module, backend, contextDataOffset);
145+
const context = new ComputeContextImpl(module, backend, contextDataOffset);
146146
return backend.computeKernel(kernel, context);
147147
});
148148
}

0 commit comments

Comments
 (0)