Skip to content

Commit 9a08f8a

Browse files
committed
adds sync wrappers
1 parent 14e7ab5 commit 9a08f8a

5 files changed

Lines changed: 283 additions & 126 deletions

File tree

cmake/example.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ if(EMSCRIPTEN)
5454
-sUSE_GLFW=3 \
5555
-sALLOW_MEMORY_GROWTH=1 -sSTACK_SIZE=15MB \
5656
-sASYNCIFY \
57-
-sASYNCIFY_DEBUG \
5857
--js-library=${DAWN_BUILD_DIR}/gen/src/emdawnwebgpu/library_webgpu_enum_tables.js \
5958
--js-library=${DAWN_BUILD_DIR}/gen/src/emdawnwebgpu/library_webgpu_generated_struct_info.js \
6059
--js-library=${DAWN_BUILD_DIR}/gen/src/emdawnwebgpu/library_webgpu_generated_sig_info.js \

examples/hello_world/run.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,19 @@ int main(int argc, char **argv) {
2828
printf("--------------\n\n");
2929

3030
// std::unique_ptr<Context> ctx = createContext();
31-
Context ctx = waitForContext();
31+
Context ctx = createContext();
3232
static constexpr size_t N = 10000;
3333
std::array<float, N> inputArr, outputArr;
3434
for (int i = 0; i < N; ++i) {
3535
inputArr[i] = static_cast<float>(i) / 10.0; // dummy input data
3636
}
3737
Tensor input = createTensor(ctx, Shape{N}, kf32, inputArr.data());
3838
Tensor output = createTensor(ctx, Shape{N}, kf32);
39-
std::future<Kernel> kernelFuture = createKernel(ctx, {kGelu, 256, kf32},
39+
Kernel op = createKernel(ctx, {kGelu, 256, kf32},
4040
Bindings{input, output},
4141
{cdiv(N, 256), 1, 1});
42-
Kernel op = waitForFuture(ctx.instance, kernelFuture);
43-
std::future<void> dispatchFuture = dispatchKernel(ctx, op);
44-
waitForFuture(ctx.instance, dispatchFuture);
45-
std::future<void> cpuFuture = toCPU(ctx, output, outputArr.data(), sizeof(outputArr));
46-
waitForFuture(ctx.instance, cpuFuture);
42+
dispatchKernel(ctx, op);
43+
toCPU(ctx, output, outputArr.data(), sizeof(outputArr));
4744
for (int i = 0; i < 12; ++i) {
4845
printf(" gelu(%.2f) = %.2f\n", inputArr[i], outputArr[i]);
4946
}

examples/render/run.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,8 @@ int main(int argc, char **argv) {
124124
cdiv({NCOLS, NROWS, 1}, wgSize), params);
125125
printf("\033[2J\033[H");
126126
while (true) {
127-
std::promise<void> promise;
128-
std::future<void> future = promise.get_future();
129-
dispatchKernel(ctx, renderKernel, promise);
130-
wait(ctx, future);
127+
128+
dispatchKernel(ctx, renderKernel);
131129
toCPU(ctx, devScreen, screen.data(), sizeof(screen));
132130
params.time = getCurrentTimeInMilliseconds() - zeroTime;
133131

0 commit comments

Comments
 (0)