forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of CallDPS (apache#3)
* Implementation of call_dps. * Implementation of PackedFuncExpr. * Test CallDPS for TIR function. * Rename. * Add header and comments. * Update. * Address comments.
- Loading branch information
1 parent
cb03c5e
commit 2d51aee
Showing
10 changed files
with
247 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# pylint: disable=wildcard-import, redefined-builtin | ||
"""Relax core operators.""" | ||
|
||
# Operators | ||
from .base import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
import tvm._ffi | ||
|
||
tvm._ffi._init_api("relax.op", __name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
from ...ir import BaseFunc | ||
from ..expr import Expr, ShapeExpr, Tuple, Call | ||
from . import _ffi_api | ||
from typing import Union, List | ||
|
||
def call_dps(shape: Union[ShapeExpr, List[int]], | ||
func: Expr, | ||
args: Union[Tuple, List[Expr]]) -> Call: | ||
""" | ||
Call a destination-passing-style function and return the output. | ||
Parameters | ||
---------- | ||
shape: ShapeExpr | ||
The output shape. | ||
func : ExternFunc or PrimFunc | ||
The destination-passing-style function. | ||
args : Tuple[Expr] | ||
The input arguments. | ||
Returns | ||
------- | ||
ret: Call | ||
A call node for the call_dps operator. | ||
""" | ||
if isinstance(shape, (list, tuple)): | ||
shape = ShapeExpr(shape) | ||
if isinstance(args, (list, tuple)): | ||
args = Tuple(args) | ||
return _ffi_api.call_dps(shape, func, args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ | |
# Span | ||
Span = base.Span | ||
SourceName = base.SourceName | ||
Id = base.Id | ||
|
||
# Type | ||
Type = ty.Type | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
#include <tvm/relay/op.h> | ||
#include <tvm/relax/expr.h> | ||
|
||
namespace tvm { | ||
namespace relax { | ||
|
||
Expr MakeCallDPS(ShapeExpr shape, Expr func, Tuple args) { | ||
static const Op& op = Op::Get("call_dps"); | ||
return Call(op, {shape, func, args}, {}, {}); | ||
} | ||
|
||
TVM_REGISTER_GLOBAL("relax.op.call_dps") | ||
.set_body_typed(MakeCallDPS); | ||
|
||
RELAY_REGISTER_OP("call_dps") | ||
.set_num_inputs(3) | ||
.add_argument("shape", "ShapeExpr", "The output shape.") | ||
.add_argument("func", "Expr", "The destination-passing-style function.") | ||
.add_argument("args", "Tuple", "The input arguments."); | ||
|
||
} // namespace relax | ||
} // namespace tvm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
import tvm | ||
from tvm import tir | ||
from tvm import relax as rx | ||
from tvm.script import ty | ||
from tvm.ir import TensorType | ||
import numpy as np | ||
|
||
@tvm.register_func("test.op.identity") | ||
def identity_packed(a): | ||
return tvm.nd.array(a.asnumpy) | ||
|
||
@tvm.script.tir | ||
def identity_tir(a: ty.handle, b: ty.handle) -> None: | ||
A = tir.match_buffer(a, [54, 96]) | ||
B = tir.match_buffer(b, [54, 96]) | ||
|
||
with tir.block([54, 96], "compute") as [vi, vj]: | ||
B[vi, vj] = A[vi, vj] | ||
|
||
|
||
def test_call_dps() -> None: | ||
shape_anno = [54, 96] | ||
type_anno = rx.DynTensorType(2, "float32") | ||
v0 = rx.Var("v0", shape_anno, type_anno) | ||
v1 = rx.call_dps([54, 96], rx.extern("test.op.identity"), [v0]) | ||
v1 = rx.call_dps([54, 96], identity_tir, [v0]) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_call_dps() |