Skip to content

Commit

Permalink
WIP: second set of mods
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Aug 23, 2021
1 parent ea399a4 commit e24818a
Show file tree
Hide file tree
Showing 72 changed files with 591 additions and 701 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ option(USE_AVX "Build code with AVX ISA support"
option(USE_AVX2 "Build code with AVX2 ISA support" OFF)
# control which projects get enabled
# Continuous Integration override to build all
option(BUILD_CI_CHECK "Set to ON to build all components" OFF)
option(BUILD_ALL "Set to ON to build all components" OFF)
# or subsets of the components
option(BUILD_DEMONSTRATION "Set to ON to build all demonstration components" ON)
option(BUILD_NUMERICAL_CHECKS "Set to ON to build all the numerical components" OFF)
Expand Down Expand Up @@ -481,7 +481,7 @@ install(FILES
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/${project_library_target_name}
DESTINATION ${include_install_dir})

if(BUILD_CI_CHECK)
if(BUILD_ALL)
# set the grouped components to build (will trigger builds when tested)
set(BUILD_DEMONSTRATION ON)
set(BUILD_NUMERICAL_CHECKS ON)
Expand All @@ -502,7 +502,7 @@ if(BUILD_CI_CHECK)

# build the HW validation environment
set(BUILD_VALIDATION_HW ON)
endif(BUILD_CI_CHECK)
endif(BUILD_ALL)

if(BUILD_DEMONSTRATION)
# core demonstration example applications that use the library
Expand Down
15 changes: 7 additions & 8 deletions benchmark/accuracy/blas/dot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@

int main(int argc, char** argv)
try {
using namespace std;
using namespace sw::universal;

std::streamsize prec = cout.precision();
cout << setprecision(17);
std::streamsize prec = std::cout.precision();
std::cout << std::setprecision(17);

{
using Scalar = decimal;
Expand All @@ -48,15 +47,15 @@ try {
Vector a = { a1, a2, a3, a4 };
Vector b = { b1, b2, b3, b4 };

cout << "a: " << a << '\n';
cout << "b: " << b << '\n';
std::cout << "a: " << a << '\n';
std::cout << "b: " << b << '\n';

cout << "\n\n";
std::cout << "\n\n";
decimal v = dot(a, b);
cout << v << (v == 2 ? " <----- PASS" : " <----- FAIL") << endl;
std::cout << v << (v == 2 ? " <----- PASS\n" : " <----- FAIL\n");
}

cout << setprecision(prec);
std::cout << std::setprecision(prec);

return EXIT_SUCCESS;
}
Expand Down
12 changes: 5 additions & 7 deletions benchmark/accuracy/blas/gemm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ std::string conditional_fdp(const sw::universal::blas::vector< Scalar >& a, cons
}
template<size_t nbits, size_t es>
std::string conditional_fdp(const sw::universal::blas::vector< sw::universal::posit<nbits, es> >& a, const sw::universal::blas::vector< sw::universal::posit<nbits, es> >& b) {
using namespace std;
stringstream ss;
std::stringstream ss;
ss << sw::universal::fdp(a, b);
return ss.str();
}
Expand All @@ -40,21 +39,20 @@ sw::universal::occurrence<sw::universal::decimal> sw::universal::decimal::ops;

int main(int argc, char** argv)
try {
using namespace std;
using namespace sw::universal::blas;

using Scalar = decimal;
using Scalar = sw::universal::decimal;
using Matrix = matrix<Scalar>;

constexpr size_t N = 5;

Matrix A = eye<Scalar>(N);
Matrix B = frank<Scalar>(N);
decimal proxy;
sw::universal::decimal proxy;
proxy.resetStats();
Matrix C = A * B;
cout << C << endl;
proxy.printStats(cout);
std::cout << C << '\n';
proxy.printStats(std::cout);

return EXIT_SUCCESS;
}
Expand Down
17 changes: 7 additions & 10 deletions benchmark/accuracy/blas/matvec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

template<typename Scalar>
void catastrophicCancellationTest() {
using namespace std;
cout << "\nScalar type : " << typeid(Scalar).name() << '\n';
std::cout << "\nScalar type : " << typeid(Scalar).name() << '\n';
using Matrix = sw::universal::blas::matrix<Scalar>;
using Vector = sw::universal::blas::vector<Scalar>;

Expand All @@ -29,25 +28,23 @@ void catastrophicCancellationTest() {
{ a1, a2, a3, a4 },
{ a1, a2, a3, a4 }
};
cout << std::setprecision(10);
cout << "matrix A: \n" << A << endl;
std::cout << std::setprecision(10);
std::cout << "matrix A: \n" << A << '\n';
Vector x = { 4.0e7, 1, -1, -1.6e8 };
cout << "vector x: \n" << x << endl;
std::cout << "vector x: \n" << x << '\n';
Vector b(2);
b = A * x;
cout << "vector b: \n" << b << endl;
std::cout << "vector b: \n" << b << '\n';
if (b[0] == 2 && b[1] == 2) {
cout << "PASS\n";
std::cout << "PASS\n";
}
else {
cout << "FAIL\n";
std::cout << "FAIL\n";
}
}

int main(int argc, char** argv)
try {
using namespace std;

catastrophicCancellationTest<float>();
catastrophicCancellationTest<double>();
catastrophicCancellationTest< sw::universal::posit<32,2> >();
Expand Down
15 changes: 7 additions & 8 deletions benchmark/energy/blas/dot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@

int main(int argc, char** argv)
try {
using namespace std;
using namespace sw::universal;

std::streamsize prec = cout.precision();
cout << setprecision(17);
std::streamsize prec = std::cout.precision();
std::cout << std::setprecision(17);

{
using Scalar = decimal;
Expand All @@ -48,15 +47,15 @@ try {
Vector a = { a1, a2, a3, a4 };
Vector b = { b1, b2, b3, b4 };

cout << "a: " << a << '\n';
cout << "b: " << b << '\n';
std::cout << "a: " << a << '\n';
std::cout << "b: " << b << '\n';

cout << "\n\n";
std::cout << "\n\n";
decimal v = dot(a, b);
cout << v << (v == 2 ? " <----- PASS" : " <----- FAIL") << endl;
std::cout << v << (v == 2 ? " <----- PASS\n" : " <----- FAIL\n");
}

cout << setprecision(prec);
std::cout << std::setprecision(prec);

return EXIT_SUCCESS;
}
Expand Down
12 changes: 5 additions & 7 deletions benchmark/energy/blas/gemm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ std::string conditional_fdp(const sw::universal::blas::vector< Scalar >& a, cons
}
template<size_t nbits, size_t es>
std::string conditional_fdp(const sw::universal::blas::vector< sw::universal::posit<nbits, es> >& a, const sw::universal::blas::vector< sw::universal::posit<nbits, es> >& b) {
using namespace std;
stringstream ss;
std::stringstream ss;
ss << sw::universal::fdp(a, b);
return ss.str();
}
Expand All @@ -40,21 +39,20 @@ sw::universal::occurrence<sw::universal::decimal> sw::universal::decimal::ops;

int main(int argc, char** argv)
try {
using namespace std;
using namespace sw::universal::blas;

using Scalar = decimal;
using Scalar = sw::universal::decimal;
using Matrix = matrix<Scalar>;

constexpr size_t N = 5;

Matrix A = eye<Scalar>(N);
Matrix B = frank<Scalar>(N);
decimal proxy;
sw::universal::decimal proxy;
proxy.resetStats();
Matrix C = A * B;
cout << C << endl;
proxy.printStats(cout);
std::cout << C << '\n';
proxy.printStats(std::cout);

return EXIT_SUCCESS;
}
Expand Down
17 changes: 7 additions & 10 deletions benchmark/energy/blas/matvec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

template<typename Scalar>
void catastrophicCancellationTest() {
using namespace std;
cout << "\nScalar type : " << typeid(Scalar).name() << '\n';
std::cout << "\nScalar type : " << typeid(Scalar).name() << '\n';
using Matrix = sw::universal::blas::matrix<Scalar>;
using Vector = sw::universal::blas::vector<Scalar>;

Expand All @@ -29,25 +28,23 @@ void catastrophicCancellationTest() {
{ a1, a2, a3, a4 },
{ a1, a2, a3, a4 }
};
cout << std::setprecision(10);
cout << "matrix A: \n" << A << endl;
std::cout << std::setprecision(10);
std::cout << "matrix A: \n" << A << '\n';
Vector x = { 4.0e7, 1, -1, -1.6e8 };
cout << "vector x: \n" << x << endl;
std::cout << "vector x: \n" << x << '\n';
Vector b(2);
b = A * x;
cout << "vector b: \n" << b << endl;
std::cout << "vector b: \n" << b << '\n';
if (b[0] == 2 && b[1] == 2) {
cout << "PASS\n";
std::cout << "PASS\n";
}
else {
cout << "FAIL\n";
std::cout << "FAIL\n";
}
}

int main(int argc, char** argv)
try {
using namespace std;

catastrophicCancellationTest<float>();
catastrophicCancellationTest<double>();
catastrophicCancellationTest< sw::universal::posit<32,2> >();
Expand Down
41 changes: 18 additions & 23 deletions benchmark/performance/arithmetic/areal/performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@

// measure performance of conversion operators
void TestConversionPerformance() {
using namespace std;
using namespace sw::universal;
cout << endl << "AREAL Conversion operator performance" << endl;
std::cout << "\nAREAL Conversion operator performance\n";

//uint64_t NR_OPS = 1000000;
}

template<typename Scalar>
void DecodeWorkload(uint64_t NR_OPS) {
using namespace std;
using namespace sw::universal;

Scalar a{ 0 };
Expand All @@ -50,23 +48,22 @@ void DecodeWorkload(uint64_t NR_OPS) {
// this shouldn't happen, but found a bug this way with areal<64,11,uint64_t> as type
if (first) {
first = false;
cout << typeid(a).name() << " :\n"
<< to_binary(a,true) << "\n"
std::cout << typeid(a).name() << " :\n"
<< to_binary(a,true) << '\n'
<< "sign : " << (s ? "-1\n" : "+1\n")
<< "exponent: " << to_binary(e,true) << "\n"
<< "fraction: " << to_binary(f,true) << "\n"
<< "ubit : " << (ubit ? "1" : "0") << endl;
<< "exponent: " << to_binary(e,true) << '\n'
<< "fraction: " << to_binary(f,true) << '\n'
<< "ubit : " << (ubit ? "1" : "0") << '\n';
}
}
}
if (success == 0) cout << "DECODE FAIL\n"; // just a quick double check that all went well
if (success == 0) std::cout << "DECODE FAIL\n"; // just a quick double check that all went well
}

// measure performance of conversion operators
void TestDecodePerformance() {
using namespace std;
using namespace sw::universal;
cout << endl << "AREAL decode operator performance" << endl;
std::cout << "\nAREAL decode operator performance\n";

uint64_t NR_OPS = 1000000;
PerformanceRunner("areal<8,2,uint8_t> decode ", DecodeWorkload< sw::universal::areal<8, 2, uint8_t> >, NR_OPS);
Expand Down Expand Up @@ -99,9 +96,8 @@ areal<64,11,uint64_t> decode 1000000 per 0.0017222sec -> 580

// measure performance of arithmetic operators
void TestArithmeticOperatorPerformance() {
using namespace std;
using namespace sw::universal;
cout << endl << "AREAL Arithmetic operator performance" << endl;
std::cout << "\nAREAL Arithmetic operator performance\n";

uint64_t NR_OPS = 1000000;

Expand Down Expand Up @@ -144,7 +140,6 @@ void TestArithmeticOperatorPerformance() {

int main()
try {
using namespace std;
using namespace sw::universal;

std::string tag = "AREAL operator performance benchmarking";
Expand All @@ -159,18 +154,18 @@ try {
blockbinary<a.fbits, typename Scalar::BlockType> f;
bool ubit{ false };
sw::universal::decode(a, s, e, f, ubit);
cout << typeid(a).name() << " :\n"
<< to_binary(a, true) << "\n"
std::cout << typeid(a).name() << " :\n"
<< to_binary(a, true) << '\n'
<< "sign : " << (s ? "-1\n" : "+1\n")
<< "exponent: " << to_binary(e, true) << "\n"
<< "fraction: " << to_binary(f, true) << "\n"
<< "ubit : " << (ubit ? "1" : "0") << endl;
<< "exponent: " << to_binary(e, true) << '\n'
<< "fraction: " << to_binary(f, true) << '\n'
<< "ubit : " << (ubit ? "1" : "0") << '\n';

cout << "nbits: " << a.nbits << endl;
cout << "es : " << a.es << endl;
cout << "fbits: " << a.fbits << endl;
std::cout << "nbits: " << a.nbits << '\n';
std::cout << "es : " << a.es << '\n';
std::cout << "fbits: " << a.fbits << '\n';

cout << "done" << endl;
std::cout << "done" << std::endl;

return EXIT_SUCCESS;
#else
Expand Down
Loading

0 comments on commit e24818a

Please sign in to comment.