-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Impl kernel hint #6883
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
Merged
jacquesqiao
merged 11 commits into
PaddlePaddle:develop
from
jacquesqiao:impl-kernel-hint
Dec 25, 2017
Merged
Impl kernel hint #6883
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f00f3c2
init kernel hint
jacquesqiao 7b815eb
fix typo
jacquesqiao d6c6868
rm unused code
jacquesqiao 5d25410
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
jacquesqiao 5c72d49
add include in op_kernel.h
jacquesqiao 3fd7c95
restore op_kernel since it will be moved to op_kernel_type
jacquesqiao 8cccc41
change force_cpu to use_cpu
jacquesqiao 4795ac1
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
jacquesqiao 888c4c5
fix compilation
jacquesqiao b9c111d
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
jacquesqiao 06ec191
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
jacquesqiao 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 hidden or 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,53 @@ | ||
| /* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. | ||
| 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 | ||
|
|
||
| namespace paddle { | ||
| namespace framework { | ||
|
|
||
| // define some kernel hint | ||
| const std::string kForceCPU = "force_cpu"; | ||
| const std::string kUseCUDNN = "use_cudnn"; | ||
| const std::string kUseMKLDNN = "use_mkldnn"; | ||
|
|
||
| struct OpKernelType { | ||
| struct Hash { | ||
| std::hash<int> hash_; | ||
| size_t operator()(const OpKernelType& key) const { | ||
| int place = key.place_.which(); | ||
| int data_type = static_cast<int>(key.data_type_); | ||
| int pre_hash = data_type << NUM_PLACE_TYPE_LIMIT_IN_BIT | | ||
| (place & ((1 << NUM_PLACE_TYPE_LIMIT_IN_BIT) - 1)); | ||
| return hash_(pre_hash); | ||
| } | ||
| }; | ||
|
|
||
| platform::Place place_; | ||
| proto::DataType data_type_; | ||
|
|
||
| OpKernelType(proto::DataType data_type, platform::Place place) | ||
| : place_(place), data_type_(data_type) {} | ||
|
|
||
| OpKernelType(proto::DataType data_type, | ||
| const platform::DeviceContext& dev_ctx) | ||
| : place_(dev_ctx.GetPlace()), data_type_(data_type) {} | ||
|
|
||
| bool operator==(const OpKernelType& o) const { | ||
| return platform::places_are_same_class(place_, o.place_) && | ||
| data_type_ == o.data_type_; | ||
| } | ||
| }; | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -404,19 +404,28 @@ void OperatorWithKernel::Run(const Scope& scope, | |
|
|
||
| // check if op[type] have kernel for kernel_key | ||
| OpKernelMap& kernels = kernels_iter->second; | ||
| auto kernel_key = GetKernelType(ctx); | ||
| auto kernel_iter = kernels.find(kernel_key); | ||
| auto actual_kernel_key = GetActualKernelType(ctx); | ||
| auto expected_kernel_key = GetExpectedKernelType(actual_kernel_key); | ||
|
Collaborator
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. if (actual_kernel_key != expected_kernel_key) {
TransformInputs(ctx, from=actual_kernel_key, to=expected_kernel_key);
}
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. this will be done in next PR~ |
||
| auto kernel_iter = kernels.find(expected_kernel_key); | ||
|
|
||
| if (kernel_iter == kernels.end()) { | ||
| PADDLE_THROW("The operator %s does not support %s", type_, kernel_key); | ||
| PADDLE_THROW("The operator %s does not support %s", type_, | ||
| expected_kernel_key); | ||
| } | ||
|
|
||
| kernel_iter->second->Compute(ctx); | ||
| } | ||
| OpKernelType OperatorWithKernel::GetKernelType( | ||
|
|
||
| OpKernelType OperatorWithKernel::GetActualKernelType( | ||
| const ExecutionContext& ctx) const { | ||
| return OpKernelType(IndicateDataType(ctx), ctx.GetPlace()); | ||
| } | ||
|
|
||
| OpKernelType OperatorWithKernel::GetExpectedKernelType( | ||
| const OpKernelType& actual_kernel_type) const { | ||
| return actual_kernel_type; | ||
| } | ||
|
|
||
| proto::DataType OperatorWithKernel::IndicateDataType( | ||
| const ExecutionContext& ctx) const { | ||
| auto& scope = ctx.scope(); | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Very bad code here
Since the
op_kernel.hcannot be include by any order.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.
rm op_kernel.h since the kernel type will be moved to op_kernel_type.h