forked from tlc-pack/relax
-
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.
* VM compiler. * Update. * Compile IRmodule; expose Python api * Add dtype contant serialization and type hint. * Address comments. * Add todos and fix lint. * Update * Update.
- Loading branch information
Showing
17 changed files
with
602 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/*! | ||
* \file tvm/relax/attrs/memory.h | ||
* \brief Attributes for memory operators. | ||
*/ | ||
#ifndef TVM_RELAX_ATTRS_MEMORY_H_ | ||
#define TVM_RELAX_ATTRS_MEMORY_H_ | ||
|
||
#include <tvm/ir/attrs.h> | ||
|
||
namespace tvm { | ||
namespace relax { | ||
/*! | ||
* \brief Options for allocating storage. | ||
*/ | ||
struct AllocStorageAttrs : public tvm::AttrsNode<AllocStorageAttrs> { | ||
DataType dtype; | ||
int device_id; | ||
int device_type; | ||
|
||
TVM_DECLARE_ATTRS(AllocStorageAttrs, "relax.attrs.AllocStorageAttrs") { | ||
TVM_ATTR_FIELD(dtype) | ||
.describe("The dtype of the tensor to allocate.") | ||
.set_default(DataType::Float(32, 1)); | ||
TVM_ATTR_FIELD(device_id).describe("The device id on which to allocate memory."); | ||
TVM_ATTR_FIELD(device_type).describe("The device type on which to allocate memory."); | ||
} | ||
}; | ||
|
||
/*! | ||
* \brief Options for allocating tensors. | ||
*/ | ||
struct AllocTensorAttrs : public tvm::AttrsNode<AllocTensorAttrs> { | ||
DataType dtype; | ||
|
||
TVM_DECLARE_ATTRS(AllocTensorAttrs, "relax.attrs.AllocTensorAttrs") { | ||
TVM_ATTR_FIELD(dtype) | ||
.describe("The dtype of the tensor to allocate.") | ||
.set_default(DataType::Float(32, 1)); | ||
} | ||
}; | ||
|
||
} // namespace relax | ||
} // namespace tvm | ||
#endif // TVM_RELAX_ATTRS_MEMORY_H_ |
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -20,3 +20,4 @@ | |
# Operators | ||
from .base import * | ||
from .tensor import * | ||
from .op_attrs 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,28 @@ | ||
# 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. | ||
"""The attributes node used for Relax operators""" | ||
from tvm.ir import Attrs | ||
import tvm._ffi | ||
|
||
@tvm._ffi.register_object("relax.attrs.AllocStorageAttrs") | ||
class AllocStorageAttrs(Attrs): | ||
"""Attributes used in alloc_storage operators""" | ||
|
||
|
||
@tvm._ffi.register_object("relax.attrs.AllocTensorAttrs") | ||
class AllocTensorAttrs(Attrs): | ||
"""Attributes used in alloc_tensor operators""" |
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,70 @@ | ||
# 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=no-else-return, unidiomatic-typecheck, undefined-variable, invalid-name, redefined-builtin | ||
""" | ||
The Relax Virtual Machine compiler. | ||
""" | ||
from typing import List, Optional, Union, Dict | ||
import tvm | ||
from . import vm, _ffi_api | ||
|
||
|
||
def compile(mod: tvm.IRModule) -> vm.Executable: | ||
"""Compile the module to VM executable. A helper function for VMCompiler. | ||
Parameters | ||
---------- | ||
mod : tvm.IRModule | ||
The Relay module to build. | ||
Returns | ||
------- | ||
exec : tvm.relax.Executable | ||
The VM executable that contains the bytecode. | ||
""" | ||
compiler = VMCompiler() | ||
compiler.compile(mod) | ||
return compiler.get_exec() | ||
|
||
|
||
class VMCompiler(object): | ||
"""Compiler that compiles module to VM executable.""" | ||
|
||
def __init__(self): | ||
self.mod = _ffi_api.VMCompiler() | ||
self._compile = self.mod["compile"] | ||
self._get_exec = self.mod["get_executable"] | ||
|
||
def compile(self, mod: tvm.IRModule) -> None: | ||
"""Compile the module to VM executable. | ||
Parameters | ||
---------- | ||
mod : tvm.IRModule | ||
The IRModule to build. | ||
""" | ||
self._compile(mod) | ||
|
||
def get_exec(self) -> vm.Executable: | ||
"""Get the VM executable. | ||
Returns | ||
------- | ||
exec : tvm.relax.Executable | ||
The VM executable that contains bytecode. | ||
""" | ||
return self._get_exec() |
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
Oops, something went wrong.