-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[WIP][TVM] Bring Your Own Codegen to TVM #4258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
487cee0
e0877e8
1b2041d
f7e299b
60004d1
fe3c486
8734d0a
590996e
5a6f955
2ffc785
c8e1499
7eef6f1
001f9c6
7febcdb
47517af
66779ec
a7380a1
d86a5f7
f4c55a5
5f8ecaf
c7c74c3
5d5c907
0dcc5d0
70d1e33
125b28f
a298f9c
7891208
b8f1db0
2736619
d950234
6fb0605
7beb0e3
5ff7fa6
cf7ac3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # 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. | ||
|
|
||
| message(STATUS "Build with relay.backend.contrib") | ||
|
|
||
| file(GLOB GCC_RELAY_CONTRIB_SRC src/relay/backend/contrib/gcc/codegen.cc) | ||
| list(APPEND COMPILER_SRCS ${GCC_RELAY_CONTRIB_SRC}) | ||
|
|
||
| list(FIND USE_EXTERN "dnnl" DNNL_IDX) | ||
| if(DNNL_IDX GREATER -1) | ||
| file(GLOB DNNL_RELAY_CONTRIB_SRC src/relay/backend/contrib/dnnl/codegen.cc) | ||
| list(APPEND COMPILER_SRCS ${DNNL_RELAY_CONTRIB_SRC}) | ||
|
|
||
| find_library(EXTERN_LIBRARY_DNNL dnnl) | ||
| list(APPEND TVM_RUNTIME_LINKER_LIBS ${EXTERN_LIBRARY_DNNL}) | ||
| file(GLOB DNNL_CONTRIB_SRC src/runtime/contrib/dnnl/*) | ||
| list(APPEND RUNTIME_SRCS ${DNNL_CONTRIB_SRC}) | ||
| message(STATUS "Use extern library: MKLDNN" ${EXTERN_LIBRARY_DNNL}) | ||
| endif() | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -268,6 +268,14 @@ class FunctionNode : public ExprNode { | |
| */ | ||
| bool IsPrimitive() const; | ||
|
|
||
| /*! | ||
| * \brief Check whether the function is an external function. | ||
| * External functions are subgraphes that supported by external libraries. | ||
| * | ||
| * \return Whether the function is external or not. | ||
| */ | ||
| bool IsExternal() const; | ||
|
|
||
| TVM_DLL static Function make(tvm::Array<Var> params, | ||
| Expr body, | ||
| Type ret_type, | ||
|
|
@@ -588,6 +596,25 @@ std::string AsText(const NodeRef& node, | |
| bool show_meta_data = true, | ||
| runtime::TypedPackedFunc<std::string(Expr)> annotate = nullptr); | ||
|
|
||
| /*! \brief namespace of the attributes that are attached to a function. */ | ||
| namespace attr { | ||
| /*! \brief Mark the function as a primitive function. */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do we mean by a "primitive" function ? |
||
| constexpr const char* kPrimitive = "Primitive"; | ||
| /*! | ||
| * \brief Mark the function as an external function that needs to be handled by | ||
| * the external codegen tool/backend. | ||
| */ | ||
| constexpr const char* kExternal = "External"; | ||
| /*! \brief Indicate if the function is a closure. */ | ||
| constexpr const char* kClosure = "Closure"; | ||
| /*! \brief Store a Var to parameter/Constant mapping on a Function. */ | ||
| constexpr const char* kParams = "__params__"; | ||
| /*! \brief Store the function name. */ | ||
| constexpr const char* kFuncName = "FuncName"; | ||
| /*! \brief Mark if the function should be avoided being optimized. */ | ||
| constexpr const char* kSkipOptimization = "SkipOptimization"; | ||
| } // namespace attr | ||
|
|
||
| } // namespace relay | ||
| } // namespace tvm | ||
| #endif // TVM_RELAY_EXPR_H_ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -576,6 +576,14 @@ TVM_DLL Pass EtaExpand(bool expand_constructor, bool expand_global_var); | |
| */ | ||
| TVM_DLL Pass PrintIR(bool show_meta_data = true); | ||
|
|
||
| /*! | ||
| * \brief Partition a Relay program into regions that can be executed on | ||
| * different backends. | ||
| * | ||
| * \return The pass. | ||
| */ | ||
| TVM_DLL Pass PartitionGraph(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should move away from graph terminology we should start to emphasize that we have more than a data-flow graph, this has led people to avoid scoping, effects, etc |
||
|
|
||
| } // namespace transform | ||
|
|
||
| /*! | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * 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 include/tvm/runtime/contrib/dnnl/dnnl_kernel.h | ||
| * \brief Use external dnnl library kernels. | ||
| */ | ||
|
|
||
| #ifndef TVM_RUNTIME_CONTRIB_DNNL_DNNL_KERNEL_H_ | ||
| #define TVM_RUNTIME_CONTRIB_DNNL_DNNL_KERNEL_H_ | ||
|
|
||
| #include "dnnl.hpp" | ||
|
|
||
| namespace tvm { | ||
| namespace runtime { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The header should be part of the internal header, (move to src/) as we don't want to expose them to users' of tvm
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I intentionally moved it from src to header. The reason was because the wrapper could then just directly include it and Otherwise, We may expect users to pass |
||
| namespace contrib { | ||
|
|
||
| using namespace dnnl; | ||
|
|
||
| extern "C" void dnnl_conv2d(float* data, float* weights, float* out, int p_N_, | ||
| int p_C_, int p_H_, int p_W_, int p_O_, int p_G_, | ||
| int p_Ph_, int p_Pw_, int p_Kh_, int p_Kw_, | ||
| int p_Sh_, int p_Sw_); | ||
|
|
||
| extern "C" void dnnl_dense(float* data, float* weight, float* out, int p_B_, | ||
| int p_I_, int p_O_); | ||
|
|
||
| extern "C" void dnnl_relu(float* data, float* out, int p_N_, int p_C_, int p_H_, | ||
| int p_W_); | ||
|
|
||
| extern "C" void dnnl_bn(float* data, float* gamma, float* beta, float* mean, | ||
| float* variance, float* out, int p_n_, int p_c_, | ||
| int p_h_, int p_w_, int p_e_); | ||
|
|
||
| extern "C" void dnnl_add(float* data, float* weight, float* out, int p_n_, | ||
| int p_c_, int p_h_, int p_w_); | ||
|
|
||
| } // namespace contrib | ||
| } // namespace runtime | ||
| } // namespace tvm | ||
| #endif // TVM_RUNTIME_CONTRIB_DNNL_DNNL_KERNEL_H_ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the number of external compilers and runtimes we may have, I think it's better for each one to have its own field in config.cmake. For example,
USE_GCCorUSE_DNNL. With this, we can be more flexible with our options for finding the compiler / runtime. For example,USE_GCC=ONvsUSE_GCC=<path to gcc>There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they should be prefixed as USE_EXTERNAL_ to make it clear this is part of the external integration if we go down that path.