-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev user op tensor support stride (#7829)
* align Parameter::contiguous() * auto format by CI * use IsViewApplicable * auto format by CI * refine * auto format by CI * revise AsStrided to support view * auto format by CI * fix view::unfold * fix doctest * fix AsStrided * raw implemetation * refine * refine * fix conflict * refine * refine * fix clang check * auto format by CI * fix bug * refine * auto format by CI * fix consistent test * fix check warning * refine * refine * refine * refine * remove useless codes * auto format by CI * refine * support stride in attr value and op kernel infer cache * refactor * multi tensorview impl * auto format by CI * format * auto format by CI * refine * auto format by CI * refine * remove checks * use select when index size is 1 * auto format by CI * make inputs contiguous in autograd interpreter * auto format by CI * fix bug * auto format by CI * remove functors' tensorcontiguous * auto format by CI * refine * refine * auto format by CI * refine * revert slice changes * refine * auto format by CI * refine * refine * fix clang check * auto format by CI * auto format by CI * remove useless fn * refine view::Transpose * refine * add view ops tets cases * refine * rename * refine * opexpr support strdie param * auto format by CI * auto format by CI * fix * auto format by CI * refine * auto format by CI * fix comments * fix comments * fix comments * refine * refine * export oneflow.has_same_tensor_storage api * auto format by CI * test has same tensor_storage * auto format by CI * fix comments * fix comment * refine * refine * auto format by CI * refine * refine * remove * auto format by CI * auto format by CI * refine * auto format by CI * refine * fix comments * refine * fix comments * refine * auto format by CI * update backward_fn * auto format by CI * fix comments * auto format by CI * fix diagonal * refine 0-shape copy check * refine * fix * update * auto format by CI * refine * refine chunk * refine * fix * remove StrideView * rm useless item * refine * remove StrideProto * refine Co-authored-by: oneflow-ci-bot <ci-bot@oneflow.org> Co-authored-by: Chengyu Ma <1802572599@qq.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
2f68b46
commit cdf34db
Showing
71 changed files
with
485 additions
and
198 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
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
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,83 @@ | ||
/* | ||
Copyright 2020 The OneFlow 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. | ||
*/ | ||
|
||
#include "oneflow/core/common/stride.h" | ||
#include "oneflow/core/common/protobuf.h" | ||
#include "oneflow/core/common/cplusplus_17.h" | ||
|
||
namespace oneflow { | ||
|
||
Stride::Stride(const Shape& shape) { | ||
if (shape.is_initialized()) { | ||
const int64_t ndim = shape.NumAxes(); | ||
stride_vec_.resize(shape.NumAxes()); | ||
if (ndim > 0 && shape.elem_cnt() > 0) { | ||
std::exclusive_scan(shape.dim_vec().rbegin(), shape.dim_vec().rend(), stride_vec_.rbegin(), 1, | ||
std::multiplies<>{}); | ||
} else if (ndim > 0 && shape.elem_cnt() == 0) { | ||
// 0-size shape | ||
std::vector<int64_t> tmp_shape(ndim); | ||
for (int64_t i = 0; i < ndim; ++i) { tmp_shape[i] = shape.At(i) > 0 ? shape.At(i) : 1; } | ||
std::exclusive_scan(tmp_shape.rbegin(), tmp_shape.rend(), stride_vec_.rbegin(), 1, | ||
std::multiplies<>{}); | ||
} | ||
} | ||
} | ||
|
||
Stride::Stride(const std::shared_ptr<Shape>& shape) : Stride(*shape) {} | ||
|
||
Stride::Stride(const std::initializer_list<int64_t>& stride_vec) : stride_vec_(stride_vec) {} | ||
Stride::Stride(const DimVector& stride_vec) : stride_vec_(stride_vec) {} | ||
Stride::Stride(DimVector&& stride_vec) : stride_vec_(std::move(stride_vec)) {} | ||
Stride::Stride(const Int64ListProto& stride_proto) { | ||
stride_vec_.assign(stride_proto.dim().begin(), stride_proto.dim().end()); | ||
} | ||
|
||
Stride& Stride::assign(const DimVector& stride_vec) { | ||
stride_vec_ = stride_vec; | ||
return *this; | ||
} | ||
|
||
Stride& Stride::CheckNumAxesIdenticalAndAssign(const Stride& stride) { | ||
CHECK_EQ(NumAxes(), stride.NumAxes()); | ||
stride_vec_.assign(stride.StrideVec().begin(), stride.StrideVec().end()); | ||
return *this; | ||
} | ||
|
||
Stride& Stride::operator=(const Stride& stride) { | ||
stride_vec_ = stride.stride_vec_; | ||
return *this; | ||
} | ||
|
||
bool Stride::operator==(const Stride& rhs) const { return stride_vec_ == rhs.stride_vec_; } | ||
|
||
std::string Stride::ToString() const { | ||
std::stringstream ss; | ||
int32_t idx = 0; | ||
ss << "("; | ||
for (int64_t dim : stride_vec_) { | ||
ss << dim; | ||
if (++idx != stride_vec_.size() || stride_vec_.size() == 1) { ss << ","; } | ||
} | ||
ss << ")"; | ||
return ss.str(); | ||
} | ||
|
||
void Stride::ToProto(Int64ListProto* ret) const { | ||
*(ret->mutable_dim()) = PbRf<int64_t>(stride_vec_.begin(), stride_vec_.end()); | ||
} | ||
|
||
} // namespace oneflow |
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
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.