To use managed memory, compile the code defining MANAGED To use CUDA 8 page-fault memory, compile the code defining PAGEFAULT
59 lines
1.2 KiB
C++
59 lines
1.2 KiB
C++
|
|
// Copyright (c) 2015-16 Tom Deakin, Simon McIntosh-Smith,
|
|
// University of Bristol HPC
|
|
//
|
|
// For full license terms please see the LICENSE file distributed with this
|
|
// source code
|
|
|
|
#pragma once
|
|
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <sstream>
|
|
|
|
#include "Stream.h"
|
|
|
|
#if defined(PAGEFAULT)
|
|
#define IMPLEMENTATION_STRING "CUDA - Page Fault"
|
|
#elif defined(MANAGED)
|
|
#define IMPLEMENTATION_STRING "CUDA - Managed Memory"
|
|
#else
|
|
#define IMPLEMENTATION_STRING "CUDA"
|
|
#endif
|
|
|
|
#define TBSIZE 1024
|
|
#define DOT_NUM_BLOCKS 256
|
|
|
|
template <class T>
|
|
class CUDAStream : public Stream<T>
|
|
{
|
|
protected:
|
|
// Size of arrays
|
|
unsigned int array_size;
|
|
|
|
// Host array for partial sums for dot kernel
|
|
T *sums;
|
|
|
|
// Device side pointers to arrays
|
|
T *d_a;
|
|
T *d_b;
|
|
T *d_c;
|
|
T *d_sum;
|
|
|
|
|
|
public:
|
|
|
|
CUDAStream(const unsigned int, const int);
|
|
~CUDAStream();
|
|
|
|
virtual void copy() override;
|
|
virtual void add() override;
|
|
virtual void mul() override;
|
|
virtual void triad() override;
|
|
virtual T dot() override;
|
|
|
|
virtual void init_arrays(T initA, T initB, T initC) override;
|
|
virtual void read_arrays(std::vector<T>& a, std::vector<T>& b, std::vector<T>& c) override;
|
|
|
|
};
|