Skip to content

Commit 3004b5d

Browse files
committed
Revert "Decrease number of bytes used by uninitialized tokens_ in KernelFunction (pytorch#160764)"
This reverts commit 30384ab. (cherry picked from commit cd45fe7)
1 parent 492e246 commit 3004b5d

File tree

2 files changed

+10
-34
lines changed

2 files changed

+10
-34
lines changed

aten/src/ATen/core/boxing/KernelFunction.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ class TORCH_API KernelFunction final {
9797
KernelFunction();
9898
~KernelFunction();
9999

100-
KernelFunction(const KernelFunction& other);
101-
KernelFunction& operator=(const KernelFunction& other);
100+
KernelFunction(const KernelFunction&) = default;
101+
KernelFunction& operator=(const KernelFunction&) = default;
102102

103103
KernelFunction(KernelFunction&&) noexcept = default;
104104

@@ -276,6 +276,10 @@ class TORCH_API KernelFunction final {
276276
// Register a token to be invalidated when this KernelFunction is destroyed
277277
void registerToken(std::weak_ptr<KernelToken> token) const;
278278

279+
// List of tokens that need to be invalidated when this KernelFunction is
280+
// destroyed
281+
mutable std::vector<std::weak_ptr<KernelToken>> tokens_;
282+
279283
private:
280284
explicit KernelFunction(
281285
std::unique_ptr<OperatorKernel> functor,
@@ -290,9 +294,6 @@ class TORCH_API KernelFunction final {
290294
BoxedKernel boxed_kernel_func_;
291295
void* unboxed_kernel_func_;
292296
void* sym_unboxed_kernel_func_;
293-
// List of tokens that need to be invalidated when this KernelFunction is
294-
// destroyed (lazy allocation to save memory when empty)
295-
mutable std::unique_ptr<std::vector<std::weak_ptr<KernelToken>>> tokens_;
296297
};
297298

298299
// Token held by SafeKernelFunction that gets invalidated when KernelFunction is

aten/src/ATen/core/boxing/KernelFunction_impl.h

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,13 @@ inline KernelFunction::KernelFunction()
2525
sym_unboxed_kernel_func_(nullptr) {}
2626

2727
inline KernelFunction::~KernelFunction() {
28-
if (tokens_) {
29-
for (auto& weak_token : *tokens_) {
30-
if (auto token = weak_token.lock()) {
31-
token->invalidate();
32-
}
28+
for (auto& weak_token : tokens_) {
29+
if (auto token = weak_token.lock()) {
30+
token->invalidate();
3331
}
3432
}
3533
}
3634

37-
inline KernelFunction::KernelFunction(const KernelFunction& other)
38-
: boxed_kernel_func_(other.boxed_kernel_func_),
39-
unboxed_kernel_func_(other.unboxed_kernel_func_),
40-
sym_unboxed_kernel_func_(other.sym_unboxed_kernel_func_) {
41-
// tokens_ is intentionally not copied as we only care about invalidating
42-
// tokens if the original KernelFunction is destroyed
43-
}
44-
45-
inline KernelFunction& KernelFunction::operator=(const KernelFunction& other) {
46-
if (this != &other) {
47-
boxed_kernel_func_ = other.boxed_kernel_func_;
48-
unboxed_kernel_func_ = other.unboxed_kernel_func_;
49-
sym_unboxed_kernel_func_ = other.sym_unboxed_kernel_func_;
50-
51-
// tokens_ is intentionally not copied as we only care about invalidating
52-
// tokens if the original KernelFunction is destroyed
53-
}
54-
return *this;
55-
}
56-
5735
inline KernelFunction::KernelFunction(
5836
std::unique_ptr<OperatorKernel> functor,
5937
InternalBoxedKernelFunction* boxed_kernel_func,
@@ -189,10 +167,7 @@ C10_ALWAYS_INLINE Return KernelFunction::call(
189167

190168
inline void KernelFunction::registerToken(
191169
std::weak_ptr<KernelToken> token) const {
192-
if (!tokens_) {
193-
tokens_ = std::make_unique<std::vector<std::weak_ptr<KernelToken>>>();
194-
}
195-
tokens_->push_back(std::move(token));
170+
tokens_.push_back(std::move(token));
196171
}
197172

198173
inline KernelFunction KernelFunction::makeFromBoxedKernel(

0 commit comments

Comments
 (0)