Example #1
0
def test_redundant_kernels():
    dtype = "float32"
    A = te.placeholder(shape=(1, ), name="A", dtype=dtype)
    B = te.placeholder(shape=(1, ), name="B", dtype=dtype)
    C = te.placeholder(shape=(1, ), name="C", dtype=dtype)
    D = topi.less(A, C)
    E = topi.less(B, C)
    F = topi.logical_or(D, E)
    G = topi.identity(F)

    for target in ["opencl", "cuda"]:
        if not tvm.testing.device_enabled(target):
            continue
        print("Running on target: %s" % target)
        valid = [None]

        with tvm.target.Target(target):
            s = tvm.topi.testing.get_reduce_schedule(target)(G)

        with tvm.transform.PassContext(config={
                "tir.add_lower_pass": [(2,
                                        get_verify_pass(valid, max_kernels=1))]
        }):
            tvm.build(s, [A, B, C, G], target)
        assert valid[0]
Example #2
0
def simulated_quantize_compute(attrs, inputs, out_type):
    """Compiler for simulated_quantize."""
    assert len(inputs) == 4
    assert attrs.sign
    assert attrs.rounding == "round"

    data, scale, clip_min, clip_max = inputs

    if attrs.kind == QAnnotateKind.IDENTITY:
        return [topi.identity(data)]

    # simulate rounding error
    scaled_data = topi.divide(data, scale)
    clipped_data = topi.maximum(topi.minimum(scaled_data, clip_max), clip_min)
    round_data = topi.round(clipped_data)

    # recover data
    rdata = topi.multiply(round_data, scale)
    return [rdata]