From 488fa2e37b8cb43c7809c7a3bcd2afe879ae6653 Mon Sep 17 00:00:00 2001 From: cyy Date: Tue, 31 Oct 2023 10:07:36 -0700 Subject: [PATCH] Delete copy and move operations of some Matrix classes (#2103) Summary: Pull Request resolved: https://github.com/pytorch/FBGEMM/pull/2103 For those matrices managing their buffers, the copy and move operations should be deleted to avoid default versions generated by the compiler. Another solution is to manage the buffer ownership in user defined versions, but deleting them is simpler given that no memory corruption has been found since it can be inferred that they are not used. Another solution is use std::share_ptr to manager buffers. However, it will incur some atomic operations on the reference counter, which is not desirable . Pull Request resolved: https://github.com/pytorch/FBGEMM/pull/2100 Reviewed By: spcyppt Differential Revision: D50822752 Pulled By: q10 fbshipit-source-id: 87c0a495c146c23e8f5a284ac87357990578d8d8 --- include/fbgemm/Fbgemm.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/include/fbgemm/Fbgemm.h b/include/fbgemm/Fbgemm.h index 9a7e1bee7f..eb1f3a01b7 100644 --- a/include/fbgemm/Fbgemm.h +++ b/include/fbgemm/Fbgemm.h @@ -77,6 +77,10 @@ template class PackMatrix { public: PackMatrix() = delete; // no default constructor + PackMatrix(const PackMatrix&) = delete; // no copy + PackMatrix& operator==(const PackMatrix&) = delete; // no copy + PackMatrix(PackMatrix&&) = delete; // no move + PackMatrix& operator==(PackMatrix&& rhs) noexcept = delete; // no move /** * @param rows total number of rows in the matrix @@ -296,7 +300,7 @@ class PackMatrix { std::int32_t bcol_; ///< the number of columns in each block std::int32_t nbrow_; ///< the number of blocks along rows std::int32_t nbcol_; ///< the number of blocks along columns - bool bufAllocatedHere_; + bool bufAllocatedHere_{false}; const BlockingFactors* blocking_params; ///< MCB, KCB, NCB, MR, NR, NR_MIN, ROW_INTERLEAVE; @@ -505,6 +509,13 @@ class FBGEMM_API PackWeightMatrixForGConv { using accType = accT; PackWeightMatrixForGConv() = delete; // no default constructor + PackWeightMatrixForGConv(const PackWeightMatrixForGConv&) = delete; // no copy + PackWeightMatrixForGConv& operator==(const PackWeightMatrixForGConv&) = + delete; // no copy + + PackWeightMatrixForGConv(PackWeightMatrixForGConv&&) = delete; // no move + PackWeightMatrixForGConv& operator==(PackWeightMatrixForGConv&&) = + delete; // no move /** * @param pmat if nullptr, a buffer is allocated and owned by this class. @@ -550,7 +561,7 @@ class FBGEMM_API PackWeightMatrixForGConv { const conv_param_t conv_param_; const T* sdata_; T* pdata_; - bool bufAllocatedHere_; + bool bufAllocatedHere_{false}; // Number of groups we work at a time to fill the full simd width int GTogether_; @@ -836,8 +847,8 @@ class FBGEMM_API PackAWithRowOffset final matrix_op_t trans_; const T* smat_; std::uint32_t ld_; - std::int32_t* row_offset_; - bool rowOffsetAllocatedHere; + std::int32_t* row_offset_{nullptr}; + bool rowOffsetAllocatedHere{false}; std::int32_t row_interleave_B_; }; @@ -930,8 +941,8 @@ class FBGEMM_API PackAWithQuantRowOffset final std::int32_t ld_; float scale_; std::int32_t zero_pt_; - std::int32_t* row_offset_; - bool rowOffsetAllocatedHere; + std::int32_t* row_offset_{nullptr}; + bool rowOffsetAllocatedHere{false}; std::int32_t row_interleave_B_; };