Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

h p c h elpers. h p p #ifndef HPC _ HELPERS _ HPP #define HPC _ HELPERS _ HPP #include #include #ifndef _ _

hpchelpers.hpp
#ifndef HPC_HELPERS_HPP
#define HPC_HELPERS_HPP
#include
#include
#ifndef __CUDACC__
#include
#endif
#ifndef __CUDACC__
#define TIMERSTART(label)\
std::chrono::time_point a##label, b##label; \
a##label = std::chrono::system_clock::now();
#else
#define TIMERSTART(label)\
cudaEvent_t start##label, stop##label; \
float time##label; \
cudaEventCreate(&start##label); \
cudaEventCreate(&stop##label); \
cudaEventRecord(start##label, 0);
#endif
#ifndef __CUDACC__
#define TIMERSTOP(label)\
b##label = std::chrono::system_clock::now(); \
std::chrono::duration delta##label = b##label-a##label; \
std::cout "# elapsed time (" #label "): "\
delta##label.count()"s" std::endl;
#else
#define TIMERSTOP(label)\
cudaEventRecord(stop##label, 0); \
cudaEventSynchronize(stop##label); \
cudaEventElapsedTime(&time##label, start##label, stop##label); \
std::cout "TIMING: " time##label " ms (" #label ")"\
std::endl;
#endif
#ifdef __CUDACC__
#define CUERR {\
cudaError_t err; \
if ((err = cudaGetLastError())!= cudaSuccess){\
std::cout "CUDA error: " cudaGetErrorString(err)" : "\
__FILE__", line "__LINE__ std::endl; \
exit(1); \
}\
}
// transfer constants
#define H2D (cudaMemcpyHostToDevice)
#define D2H (cudaMemcpyDeviceToHost)
#define H2H (cudaMemcpyHostToHost)
#define D2D (cudaMemcpyDeviceToDevice)
#endif
// safe division
#define SDIV(x,y)(((x)+(y)-1)/(y))
// no_init_t
#include
template
class no_init_t {
public:
static_assert(std::is_fundamental::value &&
std::is_arithmetic::value,
"wrapped type must be a fundamental, numeric type");
//do nothing
constexpr no_init_t() noexcept {}
//convertible from a T
constexpr no_init_t(T value) noexcept: v_(value){}
//act as a T in all conversion contexts
constexpr operator T () const noexcept { return v_; }
// negation on value and bit level
constexpr no_init_t& operator -() noexcept { v_=-v_; return *this; }
constexpr no_init_t& operator ~ () noexcept { v_= ~v_; return *this; }
// prefix increment/decrement operators
constexpr no_init_t& operator ++() noexcept { v_++; return *this; }
constexpr no_init_t& operator --() noexcept { v_--; return *this; }
// postfix increment/decrement operators
constexpr no_init_t operator ++(int) noexcept {
auto old(*this);
v_++;
return old;
}
constexpr no_init_t operator --(int) noexcept {
auto old(*this);
v_--;
return old;
}
// assignment operators
constexpr no_init_t& operator +=(T v) noexcept { v_+= v; return *this; }
constexpr no_init_t& operator -=(T v) noexcept { v_-= v; return *this; }
constexpr no_init_t& operator *=(T v) noexcept { v_*= v; return *this; }
constexpr no_init_t& operator /=(T v) noexcept { v_/= v; return *this; }
// bit-wise operators
constexpr no_init_t& operator &=(T v) noexcept { v_ &= v; return *this; }
constexpr no_init_t& operator |=(T v) noexcept { v_|= v; return *this; }
constexpr no_init_t& operator ^=(T v) noexcept { v_^= v; return *this; }
constexpr no_init_t& operator >>=(T v) noexcept { v_>>= v; return *this; }
constexpr no_init_t& operator =(T v) noexcept { v_= v; return *this; }
private:
T v_;
};
#endif
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

How is strategic management changing?

Answered: 1 week ago