Skip to content

Commit

Permalink
Merge pull request #109 from PRUNERS/issue107-simplify-test-input
Browse files Browse the repository at this point in the history
Issue107 simplify test input
  • Loading branch information
mikebentley15 authored Jan 26, 2018
2 parents 622853b + 84eea5c commit 2fd680a
Show file tree
Hide file tree
Showing 44 changed files with 1,466 additions and 1,680 deletions.
4 changes: 2 additions & 2 deletions data/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ runbuild: $(TARGETS) $(CUTARGETS) groundtruth

.PHONY: clean
clean:
# Here we do it this way because we were running into the error of too many
# arguments given to rm.
@# Here we do it this way because we were running into the error of too many
@# arguments given to rm.
$(foreach obj,$(OBJ_CLEAN),rm -f $(obj);)
$(foreach obj,$(DEP_CLEAN),rm -f $(obj);)
-rmdir $(OBJ_DIR)
Expand Down
19 changes: 9 additions & 10 deletions data/tests/Empty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

template <typename T>
GLOBAL
void Empty_kernel(const flit::CuTestInput<T>* tiList, double* results) {
void Empty_kernel(const T* tiList, size_t n, double* results) {
#ifdef __CUDA__
auto idx = blockIdx.x * blockDim.x + threadIdx.x;
#else
auto idx = 0;
#endif
auto& ti = tiList[idx];
results[idx] = ti.vals[0];
const T* ti = tiList + (idx*n);
results[idx] = ti[0];
}

/** An example test class to show how to make FLiT tests
Expand All @@ -27,7 +27,7 @@ class Empty : public flit::TestBase<T> {
/** Specify how many floating-point inputs your algorithm takes.
*
* Can be zero. If it is zero, then getDefaultInput should return an empty
* TestInput object which is as simple as "return {};"
* std::vector, which is as simple as "return {};"
*/
virtual size_t getInputsPerRun() override { return 1; }

Expand All @@ -38,12 +38,10 @@ class Empty : public flit::TestBase<T> {
* time with getInputsPerRun() elements in ti.vals.
*
* If your algorithm takes no inputs, then you can simply return an empty
* TestInput object. It is as simple as "return {};".
* std::vector object. It is as simple as "return {};".
*/
virtual flit::TestInput<T> getDefaultInput() override {
flit::TestInput<T> ti;
ti.vals = { 1.0 };
return ti;
virtual std::vector<T> getDefaultInput() override {
return { 1.0 };
}

/** Custom comparison methods
Expand Down Expand Up @@ -108,7 +106,8 @@ class Empty : public flit::TestBase<T> {
* The value returned by run_impl is the same value used in compare()
* implemented above.
*/
virtual flit::Variant run_impl(const flit::TestInput<T>& ti) override {
virtual flit::Variant run_impl(const std::vector<T> &ti) override {
FLIT_UNUSED(ti);
return flit::Variant();
}

Expand Down
4 changes: 2 additions & 2 deletions documentation/writing-test-cases.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ empty `run_impl()` function like the following:

```c++
// Default implementation does nothing
virtual flit::Variant run_impl(const flit::TestInput<T>& ti) override {
virtual flit::Variant run_impl(const std::vector<T>& ti) override {
FLIT_UNUSED(ti);
return flit::Variant();
}
Expand All @@ -53,7 +53,7 @@ meaningful:
```c++
template<>
flit::Variant MyTestClass<double>::run_impl(const flit::TestInput<double>& ti) {
flit::Variant MyTestClass<double>::run_impl(const std::vector<double>& ti) {
// test logic here ...
return something_meaningful;
}
Expand Down
25 changes: 14 additions & 11 deletions gensrc/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
# - input_count: how many inputs the test will take
# - default_input: populate ti.vals vector.
# - vars_initialize: initialize scope variable for the test using ti.vals
# - cu_vars_initialize: initialize scope variables for the test in CUDA using tiList[idx].vals
# - cu_vars_initialize: initialize scope variables for the test in CUDA using
# tiList[idx].vals
# - func_body: test body that is shared between cuda and non-cuda. Populate score
template_string = '''
#include "flit.h"
template <typename T>
GLOBAL
void
{name}Kernel(const flit::CuTestInput<T>* tiList, double* results) {{
{name}Kernel(const T* const* tiList, double* results) {{
#ifdef __CUDA__
auto idx = blockIdx.x * blockDim.x + threadIdx.x;
#else
Expand All @@ -40,8 +41,8 @@ class {name} : public flit::TestBase<T> {{
: flit::TestBase<T>(std::move(id)) {{}}
virtual size_t getInputsPerRun() override {{ return {input_count}; }}
virtual flit::TestInput<T> getDefaultInput() override {{
flit::TestInput<T> ti;
virtual std::vector<T> getDefaultInput() override {{
std::vector<T> ti;
{default_input}
Expand All @@ -54,11 +55,11 @@ class {name} : public flit::TestBase<T> {{
}}
virtual
flit::Variant run_impl(const flit::TestInput<T>& ti) override {{
flit::Variant run_impl(const std::vector<T>& ti) override {{
T score = 0.0;
flit::info_stream << id << ": Starting test with parameters" << std::endl;
for (T val : ti.vals) {{
for (T val : ti) {{
flit::info_stream << id << ": " << val << std::endl;
}}
Expand Down Expand Up @@ -93,11 +94,11 @@ def __init__(self, name, default_input_vals):

# setup the test
self.default_input_lines = [
'ti.vals.push_back({0});'.format(x) for x in default_input_vals]
'ti.push_back({0});'.format(x) for x in default_input_vals]
self.vars_initialize_lines = [
'T in_{0} = ti.vals[{0}];'.format(i+1) for i in range(self.input_count)]
'T in_{0} = ti[{0}];'.format(i+1) for i in range(self.input_count)]
self.cu_vars_initialize_lines = [
'T in_{0} = tiList[idx].vals[{0}];'.format(i+1) for i in range(self.input_count)]
'T in_{0} = tiList[idx][{0}];'.format(i+1) for i in range(self.input_count)]

# Create an environment for the function body
env = Environment({
Expand All @@ -109,9 +110,11 @@ def __init__(self, name, default_input_vals):
self.func_body_lines = []
for i in range(10):
var = Variable('e{0}'.format(i+1), 'T')
self.func_body_lines.append('{0} {1} = {2};'.format(var.type, var.name, random_expression(env, 3)))
self.func_body_lines.append('{0} {1} = {2};'.format(var.type, var.name,
random_expression(env, 3)))
env[var.name] = var
self.func_body_lines.append('score = {0};'.format(random_expression(env, 4, vars_only=True)))
self.func_body_lines.append('score = {0};'.format(random_expression(env, 4,
vars_only=True)))

def write(self, directory='.'):
'''
Expand Down
7 changes: 3 additions & 4 deletions inputGen/groundtruth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ namespace {
runGroundtruth_impl(std::string testName,
std::function<T()> randGen)
{
using flit::TestInput;
using flit::Vector;

auto test = flit::getTests()[testName]->get<T>();
TestInput<T> input = test->getDefaultInput();
input.vals = Vector<T>(test->getInputsPerRun(), randGen).getData();
auto input = test->getDefaultInput();
input = Vector<T>(test->getInputsPerRun(), randGen).getData();
auto scores = test->run(input);

// Return only the first score. Ignore the key
return { input.vals, std::get<0>(scores.begin()->second) };
return { input, std::get<0>(scores.begin()->second) };
}
} // end of unnamed namespace

Expand Down
5 changes: 1 addition & 4 deletions inputGen/testbed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ namespace {
runTestbed_impl(const std::string &testName,
const std::vector<T> &inputvals)
{
using flit::TestInput;
using flit::Vector;

auto test = flit::getTests()[testName]->get<T>();
TestInput<T> input = test->getDefaultInput();
input.vals = inputvals;
auto scores = test->run(input);
auto scores = test->run(inputvals);

// Return only the first score. Ignore the key
return std::get<0>(scores.begin()->second);
Expand Down
4 changes: 2 additions & 2 deletions litmus-tests/disabled/SimpleCHull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class SimpleCHull: public flit::TestBase<T> {
SimpleCHull(std::string id) : flit::TestBase<T>(std::move(id)) {}

virtual size_t getInputsPerRun(){ return 0; }
virtual flit::TestInput<T> getDefaultInput(){ return {}; }
virtual std::vector<T> getDefaultInput(){ return {}; }

protected:
virtual flit::KernelFunction<T>* getKernel() { return nullptr; }

virtual flit::Variant run_impl(const flit::TestInput<T>& ti) {
virtual flit::Variant run_impl(const std::vector<T>& ti) {
FLIT_UNUSED(ti);
CHullEdges.clear();
PointList.clear();
Expand Down
37 changes: 16 additions & 21 deletions litmus-tests/tests/DistributivityOfMultiplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
template <typename T>
GLOBAL
void
DistOfMultKernel(const flit::CuTestInput<T>* tiList, double* results){
DistOfMultKernel(const T* tiList, size_t n, double* results){
#ifdef __CUDA__
auto idx = blockIdx.x * blockDim.x + threadIdx.x;
#else
auto idx = 0;
#endif
T a = tiList[idx].vals[0];
T b = tiList[idx].vals[1];
T c = tiList[idx].vals[2];
const T* ti = tiList + (idx*n);
T a = ti[0];
T b = ti[1];
T c = ti[2];

auto distributed = (a * c) + (b * c);
results[idx] = distributed;
Expand All @@ -34,17 +35,17 @@ class DistributivityOfMultiplication : public flit::TestBase<T> {
: flit::TestBase<T>(std::move(id)) {}

virtual size_t getInputsPerRun() override { return 3; }
virtual flit::TestInput<T> getDefaultInput() override;
virtual std::vector<T> getDefaultInput() override;

protected:
virtual flit::KernelFunction<T>* getKernel() override {
return DistOfMultKernel;
}

virtual flit::Variant run_impl(const flit::TestInput<T>& ti) override {
T a = ti.vals[0];
T b = ti.vals[1];
T c = ti.vals[2];
virtual flit::Variant run_impl(const std::vector<T>& ti) override {
T a = ti[0];
T b = ti[1];
T c = ti[2];

auto distributed = (a * c) + (b * c);

Expand All @@ -63,18 +64,16 @@ class DistributivityOfMultiplication : public flit::TestBase<T> {

// Define the inputs
template<>
inline flit::TestInput<float>
inline std::vector<float>
DistributivityOfMultiplication<float>::getDefaultInput() {
auto convert = [](uint32_t x) {
return flit::as_float(x);
};

flit::TestInput<float> ti;

// Put in canned values of previously found diverging inputs
// These are entered as hex values to maintain the exact value instead of trying
// to specify enough decimal digits to get the same floating-point value
ti.vals = {
std::vector<float> ti = {
convert(0x6b8b4567),
convert(0x65ba0c1e),
convert(0x49e753d2),
Expand Down Expand Up @@ -124,18 +123,16 @@ DistributivityOfMultiplication<float>::getDefaultInput() {
}

template<>
inline flit::TestInput<double>
inline std::vector<double>
DistributivityOfMultiplication<double>::getDefaultInput() {
auto convert = [](uint64_t x) {
return flit::as_float(x);
};

flit::TestInput<double> ti;

// Put in canned values of previously found diverging inputs
// These are entered as hex values to maintain the exact value instead of trying
// to specify enough decimal digits to get the same floating-point value
ti.vals = {
std::vector<double> ti = {
convert(0x7712d691ff8158c1),
convert(0x7a71b704fdd6a840),
convert(0x019b84dddaba0d31),
Expand Down Expand Up @@ -181,7 +178,7 @@ DistributivityOfMultiplication<double>::getDefaultInput() {
}

template<>
inline flit::TestInput<long double>
inline std::vector<long double>
DistributivityOfMultiplication<long double>::getDefaultInput() {
// Here we are assuming that long double represents 80 bits
auto convert = [](uint64_t left_half, uint64_t right_half) {
Expand All @@ -191,12 +188,10 @@ DistributivityOfMultiplication<long double>::getDefaultInput() {
return flit::as_float(val);
};

flit::TestInput<long double> ti;

// Put in canned values of previously found diverging inputs
// These are entered as hex values to maintain the exact value instead of trying
// to specify enough decimal digits to get the same floating-point value
ti.vals = {
std::vector<long double> ti = {
convert(0x2b99, 0x2bb4d082ca2e7ec7), // 3.586714e-1573
convert(0x725a, 0x14c0a0cd445b52d5), // 6.131032e+3879
convert(0x075d, 0x0bc91b713fc2fba5), // 4.278225e-4366
Expand Down
21 changes: 10 additions & 11 deletions litmus-tests/tests/DoHariGSBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
template <typename T>
GLOBAL
void
DoHGSBTestKernel(const flit::CuTestInput<T>* tiList, double* result){
DoHGSBTestKernel(const T* tiList, size_t n, double* result){
#ifdef __CUDA__
auto idx = blockIdx.x * blockDim.x + threadIdx.x;
#else
auto idx = 0;
#endif

const T* vals = tiList[idx].vals;
const T* vals = tiList + (idx*n);

flit::VectorCU<T> a(vals, 3);
flit::VectorCU<T> b(vals + 3, 3);
flit::VectorCU<T> c(vals + 6, 3);
Expand All @@ -39,20 +40,20 @@ class DoHariGSBasic: public flit::TestBase<T> {
DoHariGSBasic(std::string id) : flit::TestBase<T>(std::move(id)){}

virtual size_t getInputsPerRun() override { return 9; }
virtual flit::TestInput<T> getDefaultInput() override;
virtual std::vector<T> getDefaultInput() override;

protected:
virtual flit::KernelFunction<T>* getKernel() override { return DoHGSBTestKernel; }

virtual flit::Variant run_impl(const flit::TestInput<T>& ti) override {
virtual flit::Variant run_impl(const std::vector<T>& ti) override {
using flit::operator<<;

long double score = 0.0;

//matrix = {a, b, c};
flit::Vector<T> a = {ti.vals[0], ti.vals[1], ti.vals[2]};
flit::Vector<T> b = {ti.vals[3], ti.vals[4], ti.vals[5]};
flit::Vector<T> c = {ti.vals[6], ti.vals[7], ti.vals[8]};
flit::Vector<T> a = {ti[0], ti[1], ti[2]};
flit::Vector<T> b = {ti[3], ti[4], ti[5]};
flit::Vector<T> c = {ti[6], ti[7], ti[8]};

auto r1 = a.getUnitVector();
//crit = r1[0];
Expand Down Expand Up @@ -99,13 +100,11 @@ namespace {
} // end of unnamed namespace

template <typename T>
flit::TestInput<T> DoHariGSBasic<T>::getDefaultInput() {
std::vector<T> DoHariGSBasic<T>::getDefaultInput() {
T e = getSmallValue<T>();

flit::TestInput<T> ti;

// Just one test
ti.vals = {
std::vector<T> ti = {
1, e, e, // vec a
1, e, 0, // vec b
1, 0, e, // vec c
Expand Down
Loading

0 comments on commit 2fd680a

Please sign in to comment.