Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std::generate to generate benchmark data #156

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*~
debug*
release*
*.csv
*.out
*.err
*.log
Expand Down
60 changes: 39 additions & 21 deletions inc/core/benchmark_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,47 @@
#include <boost/noncopyable.hpp>
#pragma GCC diagnostic pop

#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <cmath>

namespace gearshifft {

template <typename RealType>
struct BenchmarkDataGenerator {
BenchmarkDataGenerator(const std::size_t) {}

RealType operator()() {
return 0.125 * (i_++ & 7);
}

private:
std::size_t i_ = 0;
};

// To avoid overflows float16 data non-zero points are limited (y[0] of FFT(x)
// is sum of input values). Overflow leads to nan or inf values and iFFT(FFT())
// cannot be validated. This method still leads to nan's when size_ >= (1<<20).
template <>
struct BenchmarkDataGenerator<float16> {
BenchmarkDataGenerator(const std::size_t size)
: sparse_values_(size > LIMIT16), quotient_(size / LIMIT16) {}

float16 operator()() {
if (sparse_values_) {
return static_cast<float16>((i_++ % quotient_ == 0) ? 0.1 : 0.0);
}
return static_cast<float16>(0.125 * (i_++ & 7));
}

private:
std::size_t i_ = 0;
const bool sparse_values_;
const std::size_t quotient_;
static constexpr std::size_t LIMIT16 = 1 << 15;
};

/**
* Singleton test data helper and container.
* Creates real and complex data on first access or when dimensions have changed.
Expand All @@ -39,6 +74,7 @@ namespace gearshifft {
using ComplexVector = std::vector<ComplexType, boost::alignment::
aligned_allocator<ComplexType,
alignof(ComplexType)> >;
using Generator = BenchmarkDataGenerator<RealType>;


static const BenchmarkDataT& data(const Extent& extents) {
Expand Down Expand Up @@ -102,26 +138,7 @@ namespace gearshifft {
// allocate variables for all test cases
data_linear_.resize(size_);

const size_t limit16 = 1<<15;
if(std::is_same<RealType, float16>::value && size_ > limit16) {
// To avoid overflows float16 data non-zero points are limited
// (y[0] of FFT(x) is sum of input values)
// Overflow leads to nan or inf values and iFFT(FFT()) cannot be validated
// This method still leads to nan's when size_ >= (1<<20)
for( size_t i=0; i<size_; ++i )
{
if( i%(size_/limit16)==0 )
data_linear_[i] = 0.1;
else
data_linear_[i] = 0.0;
}
} else {
for( size_t i=0; i<size_; ++i )
{
data_linear_[i] = 0.125*(i&7);
}
}

std::generate(data_linear_.begin(), data_linear_.end(), Generator{size_});
}

BenchmarkData() = default;
Expand All @@ -134,4 +151,5 @@ namespace gearshifft {

};
} // gearshifft

#endif
1 change: 1 addition & 0 deletions src/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ using FFTs = List<Inplace_Real,
Outplace_Complex >;
using Precisions = gearshifft::DefaultPrecisionsWithoutHalfPrecision;
using FFT_Is_Normalized = std::false_type;

#elif defined(ROCFFT_ENABLED)
#include "libraries/rocfft/rocfft.hpp"

Expand Down