This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mkldnn-v1.0] Add MKL-DNN reshape&flatten&expand_dims (#16258)
* Add mkldnn 1.0 support for reshape/flatten/expanddims ops * improve log & modify definition location of args_map_ * fix comments * rebase code * trigger CI * trigger CI * trigger CI * trigger CI
- Loading branch information
1 parent
458bb73
commit 922b616
Showing
9 changed files
with
225 additions
and
108 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
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. | ||
*/ | ||
|
||
/*! | ||
* \file mkldnn_expand_dims.cc | ||
* \brief Implement expand_dims operator via MKL-DNN reorder primitive | ||
* \author Wuxun Zhang | ||
*/ | ||
|
||
#if MXNET_USE_MKLDNN == 100 | ||
|
||
#include "mkldnn_reshape-inl.h" | ||
|
||
namespace mxnet { | ||
namespace op { | ||
|
||
class MKLDNNExpandDimsFwd : public MKLDNNReshapeFwd { | ||
public: | ||
explicit MKLDNNExpandDimsFwd(const OpReqType &req, | ||
const NDArray &input, | ||
const NDArray &output) | ||
: MKLDNNReshapeFwd(req, input, output) {} | ||
}; | ||
|
||
typedef ParamOpSign<ExpandDimParam> MKLDNNExpandDimsSignature; | ||
|
||
void MKLDNNExpandDimsForward(const nnvm::NodeAttrs &attrs, | ||
const OpContext &ctx, | ||
const NDArray &input, | ||
const OpReqType &req, | ||
const NDArray &output) { | ||
const ExpandDimParam& param = nnvm::get<ExpandDimParam>(attrs.parsed); | ||
if (req == kNullOp) return; | ||
CHECK_NE(req, kAddTo) << "kAddTo is not supported yet"; | ||
|
||
auto fwd = GetCachedForward<MKLDNNExpandDimsFwd, ExpandDimParam, | ||
MKLDNNExpandDimsSignature>(param, req, input, output); | ||
|
||
auto ws_size = fwd.GetWorkspaceSize(); | ||
void* ws_ptr = nullptr; | ||
if (ws_size) { | ||
mshadow::Stream<cpu> *s = ctx.get_stream<cpu>(); | ||
mshadow::Tensor<cpu, 1, char> ws = ctx.requested[0] | ||
.get_space_typed<cpu, 1, char>(mshadow::Shape1(ws_size), s); | ||
ws_ptr = reinterpret_cast<void*>(ws.dptr_); | ||
} | ||
|
||
fwd.Execute(input, output, req, ws_ptr); | ||
} | ||
|
||
} // namespace op | ||
} // namespace mxnet | ||
|
||
#endif |
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
Oops, something went wrong.