Skip to content

Instantly share code, notes, and snippets.

Enforce constness of SGMatrix / SGVector

Currently, one can always mutate const matrix and vector by creating shadow copy, which breaks the semantic of const reference. We can make copy ctors return deep copy and add move ctors. The move constructor should obtain the ownership of underlying memory, and leave the original one uninitialized.

For example

SGMatrix::SGMatrix(const SGMatrix &orig); // deep copy
SGMatrix& SGMatrix::operator=(const SGMatrix<T>&); // deep copy
SGMatrix(SGMatrix &&); // move ctor
import tvm
def main(n):
a = tvm.placeholder((n,), dtype='int8')
c = tvm.compute((n,), lambda i: a[i])
s = tvm.create_schedule(c.op)
bx, tx = s[c].split(s[c].op.axis[0], factor=4)
"""
Writing tunable template and Using auto-tuner
=============================================
**Author**: `Lianmin Zheng <https://https://github.com/merrymercy>`_
This is an introduction tutorial to the auto-tuning module in tvm.
There are two steps in auto-tuning.
The first step is defining a search space.
The second step is running a search algorithm to explore through this space.
import sys
import logging
import tvm
from tvm import autotvm
import topi
import numpy as np
from topi.testing import conv2d_nchw_python
import functools
import operator
import os
import nnvm
import nnvm.testing
import nnvm.compiler
from nnvm import sym
import tvm
from tvm import autotvm
from tvm.autotvm.tuner import XGBTuner, GATuner, RandomTuner, GridSearchTuner
from tvm.contrib.util import tempdir
import argparse
import json
parser = argparse.ArgumentParser()
parser.add_argument('in_file', type=str)
parser.add_argument('out_file', type=str)
args = parser.parse_args()
def transform(line):
@vinx13
vinx13 / TVM_OpenCV
Last active April 1, 2019 07:50
TVM_OpenCV
# ========
# captured on: Mon Apr 1 15:38:30 2019
# os release : 4.15.0-42-generic
# perf version : 4.15.17
# arch : x86_64
# nrcpus online : 8
# nrcpus avail : 8
# cpudesc : Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
# cpuid : GenuineIntel,6,94,3
# total memory : 16341608 kB
# ========
# captured on: Mon Apr 1 14:48:04 2019
# os release : 4.15.0-42-generic
# perf version : 4.15.17
# arch : x86_64
# nrcpus online : 8
# nrcpus avail : 8
# cpudesc : Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
# cpuid : GenuineIntel,6,94,3
# total memory : 16341608 kB
import tvm
import tvm.relay as relay
'''
fn (%cond: bool) -> float32 {
let %x = fn () -> float32 {
let %x1 = 0f /* ty=float32 */
%x1
}
let %x2 = ref(%x)
let %x3 = if (%cond) {
@vinx13
vinx13 / pe.py
Last active June 28, 2019 16:59
import tvm
import tvm.relay as relay
import tvm.relay.testing
import numpy as np
x = relay.var("x", shape=(1, 16))
y = relay.var("y", shape=(1, 16))
z = relay.var("z", shape=(1, 16))
cond = relay.var("cond", shape=(), dtype='uint1')
net = relay.If(cond, x, y)