Skip to content

Conversation

@tqchen
Copy link
Member

@tqchen tqchen commented Jul 11, 2017

cc @Javelinjs maybe some good reference on setting up testcases

@tqchen
Copy link
Member Author

tqchen commented Jul 11, 2017

Use TVM to Generate Javascript Library

The general idea is to use TVM as normally and set target to be llvm -target=asmjs-unknown-emscripten -system-lib.

The following code snippet from tests/web/prepare_test_libs.py demonstrate
the compilation process.

import tvm
from tvm.contrib import emscripten
import os
def prepare_test_libs(base_path):
    target = "llvm -target=asmjs-unknown-emscripten -system-lib"
    if not tvm.module.enabled(target):
        raise RuntimeError("Target %s is not enbaled" % target)
    n = tvm.var("n")
    A = tvm.placeholder((n,), name='A')
    B = tvm.compute(A.shape, lambda *i: A(*i) + 1.0, name='B')
    s = tvm.create_schedule(B.op)
    fadd1 = tvm.build(s, [A, B], target, name="add_one")
    obj_path = os.path.join(base_path, "test_add_one.bc")
    fadd1.save(obj_path)
    emscripten.create_js(os.path.join(base_path, "test_module.js"), obj_path)

if __name__ == "__main__":
    curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
    prepare_test_libs(os.path.join(curr_path, "../../lib"))

In this workflow, we use TVM to generate a .bc file and statically link
that with the lib/libtvm_web_runtime.bc(emscripten.create_js will help you do that).
The result js library is a library that contains both TVM runtime and the compiled function.

Run the Generated Library

The following code snippet from tests/web/test_module_load.js demonstrate
how to run the compiled library.

// Load Emscripten Module, need to change path to root/lib
const path = require("path");
process.chdir(path.join(__dirname, "../../lib"));
var Module = require("../../lib/test_module.js");
// Bootstrap TVMruntime with emscripten module.
const tvm_runtime = require("../../web/tvm_runtime.js");
const tvm = tvm_runtime.create(Module);

// Load system library, the compiled functions is registered in sysLib.
var sysLib = tvm.systemLib();

function randomArray(length, max) {
  return Array.apply(null, Array(length)).map(function() {
    return Math.random() * max;
  });
}

function testAddOne() {
  // grab pre-loaded function
  var faddOne = sysLib.getFunction("add_one");
  tvm.assert(tvm.isPackedFunc(faddOne));
  var n = 124;
  var A = tvm.empty(n).copyFrom(randomArray(n, 1));
  var B = tvm.empty(n);
  // call the function.
  faddOne(A, B);
  // verify
  for (var i = 0; i < B.length; ++i) {
    tvm.assert(B[i] == A[i] + 1);
  }
  faddOne.release();
}

testAddOne();
sysLib.release();

@tqchen tqchen closed this Jul 11, 2017
@tqchen tqchen reopened this Jul 11, 2017
@ZihengJiang ZihengJiang merged commit 0a07411 into apache:master Jul 11, 2017
Laurawly added a commit to Laurawly/tvm-1 that referenced this pull request Nov 19, 2017
tqchen pushed a commit that referenced this pull request Nov 19, 2017
* scheduler tweaked for super resolution perf

* conv2d_transpose schedule error fixed

* nnvm issue #239 fixed
tqchen pushed a commit to tqchen/tvm that referenced this pull request Jul 6, 2018
* scheduler tweaked for super resolution perf

* conv2d_transpose schedule error fixed

* nnvm issue apache#239 fixed
@phara0hcom
Copy link

phara0hcom commented Aug 8, 2018

I have a question about the tests/web/prepare_test_libs.py after following all these steps:
https://github.com/dmlc/tvm/blob/master/web/README.md

I ran prepare_test_libs.py and got the following output:

Traceback (most recent call last):
  File "./tests/web/prepare_test_libs.py", line 21, in <module>
    prepare_test_libs(os.path.join(curr_path, "../../lib"))
  File "./tests/web/prepare_test_libs.py", line 9, in prepare_test_libs
    raise RuntimeError("Target %s is not enbaled" % target)
RuntimeError: Target llvm -target=asmjs-unknown-emscripten -system-lib is not enbaled

What can I do to fix this?
Can I use a different target?
If so can how can I get a list of targets?

I can make an issue out of this

@srkreddy1238
Copy link
Contributor

What is the llvm version ?

try llc --version

@phara0hcom
Copy link

phara0hcom commented Aug 8, 2018

@srkreddy1238 this is what I get but only after I put in the following command:
source ./Documents/GitHub/emsdk/emsdk_env.sh
then I get llc as a bash command

LLVM (http://llvm.org/):
  LLVM version 6.0.1
  Optimized build.
  Default target: x86_64-apple-darwin17.7.0
  Host CPU: haswell

  Registered Targets:
    js     - JavaScript (asm.js, emscripten) backend
    x86    - 32-bit X86: Pentium-Pro and above
    x86-64 - 64-bit X86: EM64T and AMD64

else I will get an error:
-bash: llc: command not found

EDIT:

resolved the issue with bash -bash: llc: command not found by editing .bash_profile
but still have the same error as before

sergei-mironov pushed a commit to sergei-mironov/tvm that referenced this pull request Aug 8, 2018
* scheduler tweaked for super resolution perf

* conv2d_transpose schedule error fixed

* nnvm issue apache#239 fixed
areusch pushed a commit to areusch/tvm that referenced this pull request Sep 20, 2022
* B2-4: TIR IRBuilder

B2, B3 and B4 listed in apache#227.

* bypass `Literal` for lower python versions
junrushao added a commit to junrushao/tvm that referenced this pull request Oct 18, 2022
[TVMScript] B4: If branch support (apache#263)
B8: Local Function Support  (apache#258)
[TVMScript] B3: Type annotation checks (apache#256)
[TVMScript][Parser] B1: Dataflow block (apache#252)
[TVMScript] B2: match shape support (apache#251)
[TVMScript] B6/B7: Symbolic shape and var shadowing  (apache#245)
[TVMScript] B5: Support relax op (apache#244)
[TVMScript] B0: Call_tir support (apache#243)
enhance parser error reporting (apache#242)
[TVMScript] A1: Relax Parser infra (apache#240)
update ci image versions. (apache#241)
[TVMScript] B2-4: TIR IRBuilder (apache#239)
[TVMScript] A0: Relax IRBuilder infra (apache#235)
[TVMScript] B5-6: TIR IRBuilder (apache#231)
[TVMScript] B1: IRBuilder (apache#228)
[TVMScript] New Parser: Part C (apache#218)
[TVMScript] New Parser: Part A (apache#221)
[TVMScript] New Parser: Part B (apache#217)

Not recovered:
[Pass] Separate ApplyHistoryBest from tuning passes (apache#226)
[Bugfix] Couple of bug fixes to run TVM-gen code together with BYOC (apache#249)

co-authored-by: Yuchen Jin <[email protected]>
co-authored-by: Siyuan Feng <[email protected]>
co-authored-by: Ruihang Lai <[email protected]>
MasterJH5574 added a commit to MasterJH5574/tvm that referenced this pull request Nov 20, 2022
[TVMScript] B4: If branch support (apache#263)
B8: Local Function Support  (apache#258)
[TVMScript] B3: Type annotation checks (apache#256)
[TVMScript][Parser] B1: Dataflow block (apache#252)
[TVMScript] B2: match shape support (apache#251)
[TVMScript] B6/B7: Symbolic shape and var shadowing  (apache#245)
[TVMScript] B5: Support relax op (apache#244)
[TVMScript] B0: Call_tir support (apache#243)
enhance parser error reporting (apache#242)
[TVMScript] A1: Relax Parser infra (apache#240)
update ci image versions. (apache#241)
[TVMScript] B2-4: TIR IRBuilder (apache#239)
[TVMScript] A0: Relax IRBuilder infra (apache#235)
[TVMScript] B5-6: TIR IRBuilder (apache#231)
[TVMScript] B1: IRBuilder (apache#228)
[TVMScript] New Parser: Part C (apache#218)
[TVMScript] New Parser: Part A (apache#221)
[TVMScript] New Parser: Part B (apache#217)

Not recovered:
[Pass] Separate ApplyHistoryBest from tuning passes (apache#226)
[Bugfix] Couple of bug fixes to run TVM-gen code together with BYOC (apache#249)

co-authored-by: Yuchen Jin <[email protected]>
co-authored-by: Siyuan Feng <[email protected]>
co-authored-by: Ruihang Lai <[email protected]>
junrushao added a commit to junrushao/tvm that referenced this pull request Feb 8, 2023
[TVMScript] B4: If branch support (apache#263)
B8: Local Function Support  (apache#258)
[TVMScript] B3: Type annotation checks (apache#256)
[TVMScript][Parser] B1: Dataflow block (apache#252)
[TVMScript] B2: match shape support (apache#251)
[TVMScript] B6/B7: Symbolic shape and var shadowing  (apache#245)
[TVMScript] B5: Support relax op (apache#244)
[TVMScript] B0: Call_tir support (apache#243)
enhance parser error reporting (apache#242)
[TVMScript] A1: Relax Parser infra (apache#240)
update ci image versions. (apache#241)
[TVMScript] B2-4: TIR IRBuilder (apache#239)
[TVMScript] A0: Relax IRBuilder infra (apache#235)
[TVMScript] B5-6: TIR IRBuilder (apache#231)
[TVMScript] B1: IRBuilder (apache#228)
[TVMScript] New Parser: Part C (apache#218)
[TVMScript] New Parser: Part A (apache#221)
[TVMScript] New Parser: Part B (apache#217)

Not recovered:
[Pass] Separate ApplyHistoryBest from tuning passes (apache#226)
[Bugfix] Couple of bug fixes to run TVM-gen code together with BYOC (apache#249)

co-authored-by: Yuchen Jin <[email protected]>
co-authored-by: Siyuan Feng <[email protected]>
co-authored-by: Ruihang Lai <[email protected]>
yelite pushed a commit to yelite/tvm that referenced this pull request Feb 17, 2023
[TVMScript] B4: If branch support (apache#263)
B8: Local Function Support  (apache#258)
[TVMScript] B3: Type annotation checks (apache#256)
[TVMScript][Parser] B1: Dataflow block (apache#252)
[TVMScript] B2: match shape support (apache#251)
[TVMScript] B6/B7: Symbolic shape and var shadowing  (apache#245)
[TVMScript] B5: Support relax op (apache#244)
[TVMScript] B0: Call_tir support (apache#243)
enhance parser error reporting (apache#242)
[TVMScript] A1: Relax Parser infra (apache#240)
update ci image versions. (apache#241)
[TVMScript] B2-4: TIR IRBuilder (apache#239)
[TVMScript] A0: Relax IRBuilder infra (apache#235)
[TVMScript] B5-6: TIR IRBuilder (apache#231)
[TVMScript] B1: IRBuilder (apache#228)
[TVMScript] New Parser: Part C (apache#218)
[TVMScript] New Parser: Part A (apache#221)
[TVMScript] New Parser: Part B (apache#217)

Not recovered:
[Pass] Separate ApplyHistoryBest from tuning passes (apache#226)
[Bugfix] Couple of bug fixes to run TVM-gen code together with BYOC (apache#249)

co-authored-by: Yuchen Jin <[email protected]>
co-authored-by: Siyuan Feng <[email protected]>
co-authored-by: Ruihang Lai <[email protected]>
LeiWang1999 added a commit to LeiWang1999/tvm that referenced this pull request Nov 8, 2024
…he#239)

* Refactor Simplify function to handle multiple functions in IRModule

* Update submodule commit reference

* Add CUDA_DEVICE_ORDER environment variable to bashrc

* test fix

* lint fix

* Refactor test_general_matmul_bf16.py to use bitblas.testing.main()

* Update submodule commit reference

* Update Ubuntu version in install scripts based on LLVM version

* Update Ubuntu version in install scripts based on LLVM version

* Update submodule commit reference

* Update submodule commit reference

* Update submodule commit reference

* Update submodule commit reference

* Update submodule commit reference

* [Dev] Update subproject commit for TVM

* ignore profiler directories.

* MFMA Support

* lint fix

* MFMA Fixed.

* Disable Benchmark artifacts
MasterJH5574 pushed a commit to MasterJH5574/tvm that referenced this pull request Aug 17, 2025
* [kernel] finish the first version of batch attn-decode

* [fix] adjust the parameters to get better performance
junrushao added a commit to junrushao/tvm that referenced this pull request Nov 8, 2025
Upstream : https://github.com/apache/tvm-ffi.git
Branch   : main
New HEAD : 82bc7b639530558e9f666043c7145696d6fa35ba
Subject  : [FIX] Fix missing static registration for DLTensor* (apache#239)
Author   : Tianqi Chen <[email protected]>
Date     : 2025-11-07T20:17:41-05:00
Delta    : 1 commit(s) since 4bccb3eda0d5
Compare  : apache/tvm-ffi@4bccb3e...82bc7b6

This commit updates the tvm-ffi submodule to the latest upstream HEAD.
junrushao added a commit to junrushao/tvm that referenced this pull request Nov 8, 2025
Upstream : https://github.com/apache/tvm-ffi.git
Branch   : main
New HEAD : 82bc7b639530558e9f666043c7145696d6fa35ba
Subject  : [FIX] Fix missing static registration for DLTensor* (apache#239)
Author   : Tianqi Chen <[email protected]>
Date     : 2025-11-07T20:17:41-05:00
Delta    : 1 commit(s) since 4bccb3eda0d5
Compare  : apache/tvm-ffi@4bccb3e...82bc7b6

This commit updates the tvm-ffi submodule to the latest upstream HEAD.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants