mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-26 06:38:16 +08:00
Apply consistent code formatting across the repo. Add clang-format and pre-commit hooks.
This commit is contained in:
@@ -28,24 +28,24 @@
|
||||
#ifndef ASIANOPTION_H
|
||||
#define ASIANOPTION_H
|
||||
|
||||
template <typename Real>
|
||||
struct AsianOption {
|
||||
enum CallPut { Call, Put };
|
||||
template <typename Real> struct AsianOption
|
||||
{
|
||||
enum CallPut { Call, Put };
|
||||
|
||||
// Parameters
|
||||
Real spot;
|
||||
Real strike;
|
||||
Real r;
|
||||
Real sigma;
|
||||
Real tenor;
|
||||
Real dt;
|
||||
// Parameters
|
||||
Real spot;
|
||||
Real strike;
|
||||
Real r;
|
||||
Real sigma;
|
||||
Real tenor;
|
||||
Real dt;
|
||||
|
||||
// Value
|
||||
Real golden;
|
||||
Real value;
|
||||
// Value
|
||||
Real golden;
|
||||
Real value;
|
||||
|
||||
// Option type
|
||||
CallPut type;
|
||||
// Option type
|
||||
CallPut type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -65,25 +65,27 @@
|
||||
|
||||
// This is the un-specialized struct. Note that we prevent instantiation of
|
||||
// this struct by making it abstract (i.e. with pure virtual methods).
|
||||
template <typename T>
|
||||
struct SharedMemory {
|
||||
// Ensure that we won't compile any un-specialized types
|
||||
virtual __device__ T &operator*() = 0;
|
||||
virtual __device__ T &operator[](int i) = 0;
|
||||
template <typename T> struct SharedMemory
|
||||
{
|
||||
// Ensure that we won't compile any un-specialized types
|
||||
virtual __device__ T &operator*() = 0;
|
||||
virtual __device__ T &operator[](int i) = 0;
|
||||
};
|
||||
|
||||
#define BUILD_SHAREDMEMORY_TYPE(t, n) \
|
||||
template <> \
|
||||
struct SharedMemory<t> { \
|
||||
__device__ t &operator*() { \
|
||||
extern __shared__ t n[]; \
|
||||
return *n; \
|
||||
} \
|
||||
__device__ t &operator[](int i) { \
|
||||
extern __shared__ t n[]; \
|
||||
return n[i]; \
|
||||
} \
|
||||
}
|
||||
#define BUILD_SHAREDMEMORY_TYPE(t, n) \
|
||||
template <> struct SharedMemory<t> \
|
||||
{ \
|
||||
__device__ t &operator*() \
|
||||
{ \
|
||||
extern __shared__ t n[]; \
|
||||
return *n; \
|
||||
} \
|
||||
__device__ t &operator[](int i) \
|
||||
{ \
|
||||
extern __shared__ t n[]; \
|
||||
return n[i]; \
|
||||
} \
|
||||
}
|
||||
|
||||
BUILD_SHAREDMEMORY_TYPE(int, s_int);
|
||||
BUILD_SHAREDMEMORY_TYPE(unsigned int, s_uint);
|
||||
|
||||
@@ -30,18 +30,17 @@
|
||||
|
||||
#include "asianoption.h"
|
||||
|
||||
template <typename Real>
|
||||
class PricingEngine {
|
||||
public:
|
||||
PricingEngine(unsigned int numSims, unsigned int device,
|
||||
unsigned int threadBlockSize, unsigned int seed);
|
||||
void operator()(AsianOption<Real> &option);
|
||||
template <typename Real> class PricingEngine
|
||||
{
|
||||
public:
|
||||
PricingEngine(unsigned int numSims, unsigned int device, unsigned int threadBlockSize, unsigned int seed);
|
||||
void operator()(AsianOption<Real> &option);
|
||||
|
||||
private:
|
||||
unsigned int m_seed;
|
||||
unsigned int m_numSims;
|
||||
unsigned int m_device;
|
||||
unsigned int m_threadBlockSize;
|
||||
private:
|
||||
unsigned int m_seed;
|
||||
unsigned int m_numSims;
|
||||
unsigned int m_device;
|
||||
unsigned int m_threadBlockSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,30 +28,31 @@
|
||||
#ifndef TEST_H
|
||||
#define TEST_H
|
||||
|
||||
template <typename Real>
|
||||
struct Test {
|
||||
Test() : pass(false){};
|
||||
template <typename Real> struct Test
|
||||
{
|
||||
Test()
|
||||
: pass(false) {};
|
||||
|
||||
int device;
|
||||
unsigned int numSims;
|
||||
unsigned int threadBlockSize;
|
||||
unsigned int seed;
|
||||
int device;
|
||||
unsigned int numSims;
|
||||
unsigned int threadBlockSize;
|
||||
unsigned int seed;
|
||||
|
||||
bool pass;
|
||||
double elapsedTime;
|
||||
bool pass;
|
||||
double elapsedTime;
|
||||
|
||||
bool operator()();
|
||||
bool operator()();
|
||||
};
|
||||
|
||||
// Defaults are arbitrary to give sensible runtime
|
||||
#define k_sims_min 100000
|
||||
#define k_sims_max 1000000
|
||||
#define k_sims_def 100000
|
||||
#define k_sims_qa 100000
|
||||
#define k_sims_min 100000
|
||||
#define k_sims_max 1000000
|
||||
#define k_sims_def 100000
|
||||
#define k_sims_qa 100000
|
||||
#define k_bsize_min 32
|
||||
#define k_bsize_def 128
|
||||
#define k_bsize_qa 128
|
||||
#define k_seed_def 1234
|
||||
#define k_seed_qa 1234
|
||||
#define k_bsize_qa 128
|
||||
#define k_seed_def 1234
|
||||
#define k_seed_qa 1234
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user