-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rearchitecting the FDP overloads in BLAS
- Loading branch information
1 parent
e68bf50
commit 567744d
Showing
10 changed files
with
135 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
namespace sw { namespace universal { namespace blas { | ||
|
||
// overload for posits to use fused dot products | ||
template<unsigned nbits, unsigned es> | ||
vector< posit<nbits, es> > operator*(const matrix< posit<nbits, es> >& A, const vector< posit<nbits, es> >& x) { | ||
constexpr unsigned capacity = 20; // FDP for vectors < 1,048,576 elements | ||
vector< posit<nbits, es> > b(A.rows()); | ||
for (unsigned i = 0; i < A.rows(); ++i) { | ||
quire<nbits, es, capacity> q; | ||
for (unsigned j = 0; j < A.cols(); ++j) { | ||
q += quire_mul(A(i, j), x[j]); | ||
} | ||
convert(q.to_value(), b[i]); // one and only rounding step of the fused-dot product | ||
} | ||
return b; | ||
} | ||
|
||
// overload for posits uses fused dot products | ||
template<unsigned nbits, unsigned es> | ||
matrix< posit<nbits, es> > operator*(const matrix< posit<nbits, es> >& A, const matrix< posit<nbits, es> >& B) { | ||
constexpr unsigned capacity = 20; // FDP for vectors < 1,048,576 elements | ||
if (A.cols() != B.rows()) throw matmul_incompatible_matrices(incompatible_matrices(A.rows(), A.cols(), B.rows(), B.cols(), "*").what()); | ||
unsigned rows = A.rows(); | ||
unsigned cols = B.cols(); | ||
unsigned dots = A.cols(); | ||
matrix< posit<nbits, es> > C(rows, cols); | ||
for (unsigned i = 0; i < rows; ++i) { | ||
for (unsigned j = 0; j < cols; ++j) { | ||
quire<nbits, es, capacity> q; | ||
for (unsigned k = 0; k < dots; ++k) { | ||
q += quire_mul(A(i, k), B(k, j)); | ||
} | ||
convert(q.to_value(), C(i, j)); // one and only rounding step of the fused-dot product | ||
} | ||
} | ||
return C; | ||
} | ||
|
||
}}} // namespace sw::universal::blas |
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