Skip to content

Commit

Permalink
add a new constructor to PackedGemmMatrixB (#3598)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #3598

X-link: facebookresearch/FBGEMM#679

Add a new constructor to PackedGemmMatrixB. The new constructor inits class fields by copying the values of the parameters including packed matrix.

Reviewed By: dmpots

Differential Revision: D68471378

fbshipit-source-id: b8a1c1b809a5d52ef7a1d1b0039e8c0c59deea00
  • Loading branch information
helloguo authored and facebook-github-bot committed Jan 23, 2025
1 parent 6a1cadb commit 31d41dc
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion include/fbgemm/FbgemmPackMatrixB.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ struct TypeConverter {
T operator()(F) const;
};

#define PMAT_ALIGNMENT 64

/// class that performs packing of matrix in
/// row-major format into
/// internal packed blocked-row major format
Expand Down Expand Up @@ -96,6 +98,32 @@ class PackedGemmMatrixB {
initializeMemory();
}

PackedGemmMatrixB(
const int nrow,
const int ncol,
const int brow,
const int last_brow,
const int bcol,
const int nbrow,
const int nbcol,
const uint64_t size,
const int kernel_ncol_blocks,
const void* pmat)
: nrow_(nrow),
ncol_(ncol),
brow_(brow),
last_brow_(last_brow),
bcol_(bcol),
nbrow_(nbrow),
nbcol_(nbcol),
size_(size),
kernel_ncol_blocks_(kernel_ncol_blocks) {
pmat_ =
static_cast<T*>(fbgemmAlignedAlloc(PMAT_ALIGNMENT, size * sizeof(T)));
memcpy(pmat_, pmat, size * sizeof(T));
packed_ = true;
}

void initializeParam() {
if (!cpuinfo_initialize()) {
throw std::runtime_error("Failed to initialize cpuinfo!");
Expand Down Expand Up @@ -132,7 +160,8 @@ class PackedGemmMatrixB {
void initializeMemory() {
// allocate and initialize packed memory
size_ = (blockRowSize() * nbrow_) * (blockColSize() * nbcol_);
pmat_ = static_cast<T*>(fbgemmAlignedAlloc(64, matSize() * sizeof(T)));
pmat_ = static_cast<T*>(
fbgemmAlignedAlloc(PMAT_ALIGNMENT, matSize() * sizeof(T)));
memset(pmat_, 0, matSize() * sizeof(T));
}

Expand Down

0 comments on commit 31d41dc

Please sign in to comment.