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

Improvements to main.cpp #186

Merged
merged 26 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ endmacro()
# the final executable name
set(EXE_NAME babelstream)

# for chrono and some basic CXX features, models can overwrite this if required
set(CMAKE_CXX_STANDARD 11)
# for chrono, make_unique, and some basic CXX features, models can overwrite this if required
set(CMAKE_CXX_STANDARD 14)
gonzalobg marked this conversation as resolved.
Show resolved Hide resolved
gonzalobg marked this conversation as resolved.
Show resolved Hide resolved

if (NOT CMAKE_BUILD_TYPE)
message("No CMAKE_BUILD_TYPE specified, defaulting to 'Release'")
Expand Down
3 changes: 0 additions & 3 deletions src/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ template <class T>
class Stream
{
public:

virtual ~Stream(){}

// Kernels
Expand All @@ -35,10 +34,8 @@ class Stream
// Copy memory between host and device
virtual void init_arrays(T initA, T initB, T initC) = 0;
virtual void read_arrays(std::vector<T>& a, std::vector<T>& b, std::vector<T>& c) = 0;

};


// Implementation specific device functions
void listDevices(void);
std::string getDeviceName(const int);
Expand Down
105 changes: 105 additions & 0 deletions src/StreamModels.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#pragma once
#include <memory>

#if defined(CUDA)
#include "CUDAStream.h"
#elif defined(STD_DATA)
#include "STDDataStream.h"
#elif defined(STD_INDICES)
#include "STDIndicesStream.h"
#elif defined(STD_RANGES)
#include "STDRangesStream.hpp"
#elif defined(TBB)
#include "TBBStream.hpp"
#elif defined(THRUST)
#include "ThrustStream.h"
#elif defined(HIP)
#include "HIPStream.h"
#elif defined(HC)
#include "HCStream.h"
#elif defined(OCL)
#include "OCLStream.h"
#elif defined(USE_RAJA)
#include "RAJAStream.hpp"
#elif defined(KOKKOS)
#include "KokkosStream.hpp"
#elif defined(ACC)
#include "ACCStream.h"
#elif defined(SYCL)
#include "SYCLStream.h"
#elif defined(SYCL2020)
#include "SYCLStream2020.h"
#elif defined(OMP)
#include "OMPStream.h"
#elif defined(FUTHARK)
#include "FutharkStream.h"
#endif

template <typename T>
std::unique_ptr<Stream<T>> make_stream(int array_size, int deviceIndex) {
#if defined(CUDA)
// Use the CUDA implementation
return std::make_unique<CUDAStream<T>>(array_size, deviceIndex);

#elif defined(HIP)
// Use the HIP implementation
return std::make_unique<HIPStream<T>>(array_size, deviceIndex);

#elif defined(HC)
// Use the HC implementation
return std::make_unique<HCStream<T>>(array_size, deviceIndex);

#elif defined(OCL)
// Use the OpenCL implementation
return std::make_unique<OCLStream<T>>(array_size, deviceIndex);

#elif defined(USE_RAJA)
// Use the RAJA implementation
return std::make_unique<RAJAStream<T>>(array_size, deviceIndex);

#elif defined(KOKKOS)
// Use the Kokkos implementation
return std::make_unique<KokkosStream<T>>(array_size, deviceIndex);

#elif defined(STD_DATA)
// Use the C++ STD data-oriented implementation
return std::make_unique<STDDataStream<T>>(array_size, deviceIndex);

#elif defined(STD_INDICES)
// Use the C++ STD index-oriented implementation
return std::make_unique<STDIndicesStream<T>>(array_size, deviceIndex);

#elif defined(STD_RANGES)
// Use the C++ STD ranges implementation
return std::make_unique<STDRangesStream<T>>(array_size, deviceIndex);

#elif defined(TBB)
// Use the C++20 implementation
return std::make_unique<TBBStream<T>>(array_size, deviceIndex);

#elif defined(THRUST)
// Use the Thrust implementation
return std::make_unique<ThrustStream<T>>(array_size, deviceIndex);

#elif defined(ACC)
// Use the OpenACC implementation
return std::make_unique<ACCStream<T>>(array_size, deviceIndex);

#elif defined(SYCL) || defined(SYCL2020)
// Use the SYCL implementation
return std::make_unique<SYCLStream<T>>(array_size, deviceIndex);

#elif defined(OMP)
// Use the OpenMP implementation
return std::make_unique<OMPStream<T>>(array_size, deviceIndex);

#elif defined(FUTHARK)
// Use the Futhark implementation
return std::make_unique<FutharkStream<T>>(array_size, deviceIndex);

#else

#error unknown benchmark

#endif
}
35 changes: 35 additions & 0 deletions src/Unit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include <iostream>

// Units for output:
struct Unit {
enum class Kind { MegaByte, GigaByte, TeraByte, MibiByte, GibiByte, TebiByte };

Kind value;
tomdeakin marked this conversation as resolved.
Show resolved Hide resolved

explicit Unit(Kind v) : value(v) {}

double fmt(double bytes) const {
tomdeakin marked this conversation as resolved.
Show resolved Hide resolved
switch(value) {
case Kind::MibiByte: return std::pow(2.0, -20.0) * bytes;
case Kind::MegaByte: return 1.0E-6 * bytes;
case Kind::GibiByte: return std::pow(2.0, -30.0) * bytes;
case Kind::GigaByte: return 1.0E-9 * bytes;
case Kind::TebiByte: return std::pow(2.0, -40.0) * bytes;
case Kind::TeraByte: return 1.0E-12 * bytes;
default: std::cerr << "Unimplemented!" << std::endl; std::abort();
}
}

char const* str() const {
tomdeakin marked this conversation as resolved.
Show resolved Hide resolved
switch(value) {
case Kind::MibiByte: return "MiB";
case Kind::MegaByte: return "MB";
case Kind::GibiByte: return "GiB";
case Kind::GigaByte: return "GB";
case Kind::TebiByte: return "TiB";
case Kind::TeraByte: return "TB";
default: std::cerr << "Unimplemented!" << std::endl; std::abort();
}
}
};
Loading
Loading