Skip to content

Commit 8e06b5c

Browse files
helloguofacebook-github-bot
authored andcommitted
avoid extra copy in PackedGemmMatrixB constructor (#3691)
Summary: X-link: facebookresearch/FBGEMM#767 This diff modifies one of the constructors, to allow pass in pmat instead of always copying the memory. It's uses' responsibility to make sure the passed in parameter is valid. Reviewed By: hl475 Differential Revision: D69564913
1 parent a4be13a commit 8e06b5c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

include/fbgemm/FbgemmPackMatrixB.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class PackedGemmMatrixB {
108108
const int nbcol,
109109
const uint64_t size,
110110
const int kernel_ncol_blocks,
111-
const void* pmat)
111+
void* pmat)
112112
: nrow_(nrow),
113113
ncol_(ncol),
114114
brow_(brow),
@@ -118,10 +118,9 @@ class PackedGemmMatrixB {
118118
nbcol_(nbcol),
119119
size_(size),
120120
kernel_ncol_blocks_(kernel_ncol_blocks) {
121-
pmat_ =
122-
static_cast<T*>(fbgemmAlignedAlloc(PMAT_ALIGNMENT, size * sizeof(T)));
123-
memcpy(pmat_, pmat, size * sizeof(T));
121+
pmat_ = static_cast<T*>(pmat);
124122
packed_ = true;
123+
pmat_passed_in = true;
125124
}
126125

127126
void initializeParam() {
@@ -166,7 +165,9 @@ class PackedGemmMatrixB {
166165
}
167166

168167
~PackedGemmMatrixB() {
169-
fbgemmAlignedFree(pmat_);
168+
if (pmat_passed_in == false) {
169+
fbgemmAlignedFree(pmat_);
170+
}
170171
}
171172

172173
void unpackFromSrc(const matrix_op_t trans, T* src_mat) {
@@ -293,6 +294,7 @@ class PackedGemmMatrixB {
293294
int kernel_ncol_blocks_;
294295
T* pmat_;
295296
bool packed_{false};
297+
bool pmat_passed_in{false};
296298
};
297299

298300
} // namespace fbgemm

0 commit comments

Comments
 (0)