Skip to content

Commit

Permalink
polish kernel signature details
Browse files Browse the repository at this point in the history
  • Loading branch information
chenwhql committed Oct 26, 2021
1 parent 72910fa commit 8f100da
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
10 changes: 4 additions & 6 deletions paddle/fluid/framework/operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1763,14 +1763,12 @@ OpKernelType OperatorWithKernel::GetKernelTypeForVar(

KernelSignature OperatorWithKernel::GetExpectedPtenKernelArgs(
const ExecutionContext& ctx) const {
if (KernelSignatureMap::Instance().Has(Type())) {
return *(KernelSignatureMap::Instance().GetNullable(Type()));
} else {
if (!KernelSignatureMap::Instance().Has(Type())) {
KernelArgsNameMakerByOpProto maker(Info().proto_);
auto signature = std::move(maker.GetKernelSignature());
KernelSignatureMap::Instance().Insert(Type(), signature);
return signature;
KernelSignatureMap::Instance().Emplace(
Type(), std::move(maker.GetKernelSignature()));
}
return KernelSignatureMap::Instance().Get(Type());
}

pten::KernelContext OperatorWithKernel::BuildPtenKernelContext(
Expand Down
5 changes: 0 additions & 5 deletions paddle/fluid/framework/pten_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ pten::KernelKey TransOpKernelTypeToPtenKernelKey(
return pten::KernelKey(backend, layout, dtype);
}

KernelSignatureMap& KernelSignatureMap::Instance() {
static KernelSignatureMap g_kernel_signature_map;
return g_kernel_signature_map;
}

const paddle::SmallVector<std::string>&
KernelArgsNameMakerByOpProto::GetInputArgsNames() {
for (int i = 0; i < op_proto_->inputs_size(); ++i) {
Expand Down
20 changes: 19 additions & 1 deletion paddle/fluid/framework/pten_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ pten::KernelKey TransOpKernelTypeToPtenKernelKey(
// TODO(chenweihang): we can generate this map by proto info in compile time
class KernelSignatureMap {
public:
static KernelSignatureMap& Instance();
static KernelSignatureMap& Instance() {
static KernelSignatureMap g_kernel_signature_map;
return g_kernel_signature_map;
}

bool Has(const std::string& op_type) const {
return map_.find(op_type) != map_.end();
Expand All @@ -56,6 +59,12 @@ class KernelSignatureMap {
}
}

void Emplace(const std::string& op_type, KernelSignature&& signature) {
if (!Has(op_type)) {
map_.emplace(op_type, signature);
}
}

const KernelSignature* GetNullable(const std::string& op_type) const {
auto it = map_.find(op_type);
if (it == map_.end()) {
Expand All @@ -65,6 +74,15 @@ class KernelSignatureMap {
}
}

const KernelSignature& Get(const std::string& op_type) const {
auto it = map_.find(op_type);
PADDLE_ENFORCE_NE(
it, map_.end(),
platform::errors::NotFound(
"Operator `%s`'s kernel signature is not registered.", op_type));
return it->second;
}

private:
KernelSignatureMap() = default;
paddle::flat_hash_map<std::string, KernelSignature> map_;
Expand Down
6 changes: 2 additions & 4 deletions paddle/fluid/platform/flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -684,16 +684,14 @@ PADDLE_DEFINE_EXPORTED_bool(
/**
* Pt kernel related FLAG
* Name: FLAGS_run_pten_kernel
* Since Version: 2.2.0
* Since Version: 2.3.0
* Value Range: bool, default=false
* Example: FLAGS_run_pten_kernel=true would use the pt kernel to compute in the
* Op.
* Note:
*/
// TODO(chentianyu03): change default value to false before merge into develop
// branch
PADDLE_DEFINE_EXPORTED_bool(run_pten_kernel, true,
"It controls whether to use pt kernel");
"It controls whether to use pten kernel");

/**
* Distributed related FLAG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _decorate_compare_fused_all_reduce(self, model, use_device):
use_device,
init_feed_dict=init_data,
optimizer=self.optimizer,
fuse_all_optimizer_ops=False)
fuse_all_optimizer_ops=True)

def test_simple_fc_with_fuse_all_reduce(self):
self._decorate_compare_fused_all_reduce(simple_fc_net, DeviceType.CUDA)
Expand Down

1 comment on commit 8f100da

@paddle-bot-old
Copy link

@paddle-bot-old paddle-bot-old bot commented on 8f100da Oct 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵️ CI failures summary

🔍 PR: #34425 Commit ID: 8f100da contains failed CI.

🔹 Failed: PR-CI-APPROVAL

approve_failed
2021-10-26 23:08:39 正在保存至: “bk.txt”
2021-10-26 23:08:39 0K 100% 3.32M=0s
2021-10-26 23:08:39 2021-10-26 23:08:39 (3.32 MB/s) - 已保存 “bk.txt” [5/5])
2021-10-26 23:08:52 ****************
2021-10-26 23:08:52 0. You must have one RD (lanxianghit (Recommend), phlrain or luotao1) approval for changing the FLAGS, which manages the environment variables.
2021-10-26 23:08:52 1. You must have Dianhai approval for change 20+ files or add than 1000+ lines of content.
2021-10-26 23:08:52 2. You must have one RD (XiaoguangHu01,chenwhql,zhiqiu,Xreki,luotao1) approval for paddle/fluid/framework/operator.h, which manages the underlying code for fluid.
2021-10-26 23:08:52 3. You must have one RD (zhiqiu (Recommend) , phlrain) approval for the changes of paddle/fluid/pybind/op_function_generator.cc, which manages the logic of automatic generating op functions for dygraph.
2021-10-26 23:08:52 4. You must have one RD (XiaoguangHu01,chenwhql,zhiqiu,Xreki,luotao1) approval for the usage of const_cast.
2021-10-26 23:08:52 5. You must have one RD (Avin0323(Recommend) or zhouwei25 or wanghuancoder or luotao1) approval for modifying unity_build_rule.cmake which the rules of Unity Build.
2021-10-26 23:08:52 There are 6 approved errors.
2021-10-26 23:08:52 ****************
2021-10-26 23:08:52 + EXCODE=6
2021-10-26 23:08:52 + echo 'EXCODE: 6'
2021-10-26 23:08:52 EXCODE: 6
2021-10-26 23:08:52 + echo 'ipipe_log_param_EXCODE: 6'
2021-10-26 23:08:52 ipipe_log_param_EXCODE: 6
2021-10-26 23:08:52 + exit 6

🔹 Failed: PR-CI-Windows

test_failed
2021-10-27 00:54:05 The following tests FAILED:
2021-10-27 00:54:05 1069 - test_fuse_all_reduce_pass (Failed)
2021-10-27 00:54:05 1069 - test_fuse_all_reduce_pass (Failed)
2021-10-27 00:54:05 1069 - test_fuse_all_reduce_pass (Failed)
2021-10-27 00:54:05 C:\Users\Administrator\Downloads\workspace\24e555f3-5942-4f37-b9c0-623b5eb10a7f\Paddle\build>goto:eof
2021-10-27 00:54:05 C:\Users\Administrator\Downloads\workspace\24e555f3-5942-4f37-b9c0-623b5eb10a7f\Paddle\build>for /F %# in ('wmic os get localdatetime|findstr 20') do set end=%#
2021-10-27 00:54:05 C:\Users\Administrator\Downloads\workspace\24e555f3-5942-4f37-b9c0-623b5eb10a7f\Paddle\build>set end=20211027005405.480000+480
2021-10-27 00:54:05 C:\Users\Administrator\Downloads\workspace\24e555f3-5942-4f37-b9c0-623b5eb10a7f\Paddle\build>set end=1027005405
2021-10-27 00:54:05 C:\Users\Administrator\Downloads\workspace\24e555f3-5942-4f37-b9c0-623b5eb10a7f\Paddle\build>call :timestamp "1026233024" "1027005405" "1 card TestCases Total"
2021-10-27 00:54:05 C:\Users\Administrator\Downloads\workspace\24e555f3-5942-4f37-b9c0-623b5eb10a7f\Paddle\build>setlocal enabledelayedexpansion
2021-10-27 00:54:05 2331024
2021-10-27 00:54:05 "Windows 1 card TestCases Total Time: 5021s"
2021-10-27 00:54:05 ipipe_log_param_Windows_1_card_TestCases_Total_Time: 5021s
2021-10-27 00:54:05 2331024
2021-10-27 00:54:05 "Windows TestCases Total Time: 5021s"
2021-10-27 00:54:05 ipipe_log_param_Windows_TestCases_Total_Time: 5021s
2021-10-27 00:54:05 Running unit tests failed, will exit
2021-10-27 00:54:10 EXCODE: 8

🔹 Failed: PR-CI-OP-benchmark

Unknown Failed
2021-10-27 04:12:31 + echo '[tools/test_ci_op_benchmark.sh:271] [ERROR] Missing test script of "mean"(paddle/fluid/operators/mean_op.cu) in benchmark.'
2021-10-27 04:12:31 [tools/test_ci_op_benchmark.sh:271] [ERROR] Missing test script of "mean"(paddle/fluid/operators/mean_op.cu) in benchmark.
2021-10-27 04:12:31 + for op_name in '${!CHANGE_OP_MAP[@]}'
2021-10-27 04:12:31 + '[' -z '' ']'
2021-10-27 04:12:31 + exit_code=8
2021-10-27 04:12:31 + LOG '[ERROR] Missing test script of "fill_any_like"(paddle/fluid/operators/fill_any_like_op.cu) in benchmark.'
2021-10-27 04:12:31 + echo '[tools/test_ci_op_benchmark.sh:271] [ERROR] Missing test script of "fill_any_like"(paddle/fluid/operators/fill_any_like_op.cu) in benchmark.'
2021-10-27 04:12:31 [tools/test_ci_op_benchmark.sh:271] [ERROR] Missing test script of "fill_any_like"(paddle/fluid/operators/fill_any_like_op.cu) in benchmark.
2021-10-27 04:12:31 + for op_name in '${!CHANGE_OP_MAP[@]}'
2021-10-27 04:12:31 + '[' -z matmul,matmul,matmul.json,True ']'
2021-10-27 04:12:31 + '[' 8 -ne 0 ']'
2021-10-27 04:12:31 + LOG '[INFO] See https://github.com/PaddlePaddle/Paddle/wiki/PR-CI-OP-benchmark-Manual for details.'
2021-10-27 04:12:31 + echo '[tools/test_ci_op_benchmark.sh:275] [INFO] See https://github.com/PaddlePaddle/Paddle/wiki/PR-CI-OP-benchmark-Manual for details.'
2021-10-27 04:12:31 [tools/test_ci_op_benchmark.sh:275] [INFO] See https://github.com/PaddlePaddle/Paddle/wiki/PR-CI-OP-benchmark-Manual for details.
2021-10-27 04:12:31 + LOG '[INFO] Or you can apply for one RD (Avin0323(Recommend), Xreki, luotao1) approval to pass this PR.'
2021-10-27 04:12:31 + echo '[tools/test_ci_op_benchmark.sh:276] [INFO] Or you can apply for one RD (Avin0323(Recommend), Xreki, luotao1) approval to pass this PR.'
2021-10-27 04:12:31 [tools/test_ci_op_benchmark.sh:276] [INFO] Or you can apply for one RD (Avin0323(Recommend), Xreki, luotao1) approval to pass this PR.
2021-10-27 04:12:31 + exit 8
2021-10-27 04:12:31 {build code state=8}

🔹 Failed: PR-CI-Py3

test_failed
2021-10-27 04:49:28 The following tests FAILED:
2021-10-27 04:49:28 1277 - test_dist_mnist_gradient_merge (Failed)
2021-10-27 04:49:28 1332 - test_fuse_all_reduce_pass (Failed)
2021-10-27 04:49:28 1332 - test_fuse_all_reduce_pass (Failed)
2021-10-27 04:49:28 + EXCODE=8
2021-10-27 04:49:28 + echo 'EXCODE: 8'
2021-10-27 04:49:28 EXCODE: 8
2021-10-27 04:49:28 + echo 'ipipe_log_param_EXCODE: 8'
2021-10-27 04:49:28 ipipe_log_param_EXCODE: 8
2021-10-27 04:49:28 + [[ 8 -eq 0 ]]
2021-10-27 04:49:28 + set +x
2021-10-27 04:49:28 Sorry, some tests failed.
2021-10-27 04:49:28 + exit 8
2021-10-27 04:49:28 {build code state=8}

Please sign in to comment.