-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
add a subdirectory named cinn in operators and move releated files into it #37938
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e848b71
add a subdirectory named cinn in operators and move releated files in…
CtfGo 419619e
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
CtfGo 76dbee7
seperate CinnLaunchContext class from cinn_launch_op.h and put it in …
CtfGo d4a7afc
remove ShareBufferWith used in test to pass ci-approval
CtfGo 2029753
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
CtfGo 2040a90
add WITH_TESTING guard on operators/cinn
CtfGo 126e03e
take cinn_launch_op_test out ci-CINN
CtfGo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,9 @@ | ||
include(operators) | ||
register_operators(EXCLUDES cinn_launch_op) | ||
|
||
cc_library(cinn_launch_context SRCS cinn_launch_context.cc DEPS cinn) | ||
cc_test(cinn_launch_context_test SRCS cinn_launch_context_test.cc DEPS scope lod_tensor cinn_launch_context) | ||
|
||
op_library(cinn_launch_op SRCS cinn_launch_op.cc cinn_launch_op.cu.cc DEPS cinn cinn_compiler cinn_launch_context) | ||
cc_test(cinn_launch_op_test SRCS cinn_launch_op_test.cc DEPS cinn_compiler cinn_launch_op elementwise_add_op) | ||
set_tests_properties(cinn_launch_op_test PROPERTIES ENVIRONMENT "OMP_NUM_THREADS=1;runtime_include_dir=${PADDLE_BINARY_DIR}/third_party/CINN/src/external_cinn/cinn/runtime/cuda") | ||
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,104 @@ | ||
// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed 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. | ||
|
||
#pragma once | ||
|
||
#include <map> | ||
#include <memory> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <unordered_set> | ||
#include "cinn/hlir/framework/scope.h" | ||
#include "cinn/hlir/framework/tensor.h" | ||
#include "cinn/runtime/cinn_runtime.h" | ||
#include "paddle/fluid/framework/ddim.h" | ||
#include "paddle/fluid/framework/lod_tensor.h" | ||
#include "paddle/fluid/platform/place.h" | ||
|
||
namespace paddle { | ||
namespace operators { | ||
namespace details { | ||
|
||
using LoDTensor = framework::LoDTensor; | ||
using CinnTensor = ::cinn::hlir::framework::Tensor; | ||
using CinnScope = ::cinn::hlir::framework::Scope; | ||
|
||
class CinnLaunchContext { | ||
public: | ||
explicit CinnLaunchContext( | ||
const std::unordered_map<std::string, std::string>& paddle2cinn_varmap, | ||
const std::shared_ptr<CinnScope>& cinn_scope); | ||
|
||
// Return whether a Paddle variable used on compiled kernels | ||
bool IsVariableUsed(const std::string& var_name); | ||
|
||
// Assign tensor buffer to input or output variables | ||
void AssignExternalVariable(const std::string& var_name, | ||
const platform::Place& place, LoDTensor* tensor); | ||
|
||
// Assign tensor buffer to internal variables | ||
void AssignInternalVariable(const std::string& var_name, | ||
const platform::Place& place, LoDTensor* tensor); | ||
|
||
// Extract internal variable names from CinnScope | ||
// by excluding used input and output variables | ||
std::unordered_set<std::string> GetInternalVariableNames(); | ||
|
||
// Finalize all execution arguments and return them | ||
const std::map<std::string, cinn_pod_value_t>& FinalizeArguments() const; | ||
|
||
std::vector<std::unique_ptr<cinn_buffer_t>> HandoverBuffers() { | ||
return std::move(hold_buffers_); | ||
} | ||
|
||
private: | ||
// Get CinnTensor with CINN variable name | ||
CinnTensor GetCinnTensor(const std::string& var_name); | ||
|
||
// Check whether tensors from Paddle and CINN of the same variable | ||
// are equivalent in type and dimension | ||
void CheckTensorEquivalent(const std::string& var_name, | ||
const LoDTensor& paddle_tensor, | ||
const CinnTensor& cinn_tensor); | ||
|
||
// Share the buffer of a Paddle tensor to CINN by delivering memory address | ||
// to a cinn_buffer_t object | ||
std::unique_ptr<cinn_buffer_t> ShareTensorWithCinnBuffer( | ||
const platform::Place& place, bool free_mem_callback, LoDTensor* tensor); | ||
|
||
// Set an argument with (cinn name)->(paddle tensor) pair | ||
void SetArgument(const std::string& cinn_name, const platform::Place& place, | ||
bool free_mem_callback, LoDTensor* paddle_tensor); | ||
|
||
private: | ||
// a variable name map from paddle to cinn | ||
const std::unordered_map<std::string, std::string>& paddle2cinn_varmap_; | ||
// the variable scope of cinn | ||
const std::shared_ptr<CinnScope> cinn_scope_; | ||
|
||
// all variables used by compiled executable program | ||
std::unordered_set<std::string> cinn_variable_names_; | ||
|
||
// because a cinn_pod_value_t does not own the cinn_buffer_t object, | ||
// an extra stroage is necessary to keep the object and it can | ||
// not be released until runtime program finish execution. | ||
std::vector<std::unique_ptr<cinn_buffer_t>> hold_buffers_; | ||
|
||
// name to execution argument | ||
std::map<std::string, cinn_pod_value_t> name2argument_; | ||
}; | ||
|
||
} // namespace details | ||
} // namespace operators | ||
} // namespace paddle |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please add WITH_TESTING for CINN tests, like what I have done
Otherwise, if WITH_CINN=ON and WITH_TESTING=OFF, the compilation will fail.
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.
fix it