code: def test_bind():
      @script
      def vec_add(a, b):
          c = output_tensor((1000,), "float32")
          for tx in bind("threadIdx.x", 1000):
              c[tx] = a[tx] + b[tx]
          return c
  
      a = te.placeholder((1000,), dtype="float32", name="a")
      b = te.placeholder((1000,), dtype="float32", name="b")
      func, ins, outs = run_and_check(vec_add, [a, b], target="cuda")
      run_and_check(func, ins, outs=outs, target="cuda")
  
      @script
      def raw(a, b):
          c = output_tensor((1000,), "float32")
          for i in range(1000):
              c[i] = a[i] + b[i]
          return c
  
      c = raw(a, b)
      sch = te.create_schedule(c.op)
      x = te.thread_axis("threadIdx.x")
      sch[c].bind(c.op.axis[0], x)
      func, ins, outs = run_and_check(
          raw, [a, b], sch=sch, outs=[c], target="cuda"
      )
      run_and_check(func, ins, outs=outs, target="cuda")
  
      @te.hybrid.script
      def foo(a):
          c = output_tensor((a.shape[0],), a.dtype)
          total = allocate((1,), a.dtype, "local")
          len_i = a.shape[0]
          len_j = a.shape[1]
          for i in bind("threadIdx.x", len_i):
              total[0] = 0.0
              for k in const_range(len_j):
                  total[0] += a[i, k]
              c[i] = total[0]
  
          return c
  
      a = te.placeholder((8, 4), "float32")
      c = foo(a)
      s = te.create_schedule(c.op)
      ir = tvm.lower(s, [a, c])
  
      func, ins, outs = run_and_check(foo, [a], target="cuda")
      run_and_check(func, ins, outs=outs, target="cuda")
  
      @te.hybrid.script
      def max_threads(a):
          b = output_tensor(a.shape, a.dtype)
          n = a.shape[0]
          m = max_num_threads(True)
          for i in bind("threadIdx.x", m):
              for j in bind("blockIdx.x", ceil_div(n, m)):
                  if i * m + j < n:
                      b[i * m + j] = a[i * m + j] + a[i * m + j]
          return b
  
      a = te.placeholder((10000,), "float32")
      with tvm.target.Target("cuda"):
          func, ins, outs = run_and_check(
              max_threads, [a], target="cuda"
          )
          run_and_check(func, ins, outs=outs, target="cuda")
  
imports: import tvm, inspect, sys, traceback, numpy, pytest, types, os
  from tvm import te
  from tvm.contrib import utils
  from tvm.te.hybrid import script
  from tvm.te.hybrid.runtime import HYBRID_GLOBALS
  import tvm.testing
label_desc: Use image node_id 7 for calling a global function with example usage: test_bind() and returns: c, c, c, b