forked from UoB-HPC/BabelStream
-
Notifications
You must be signed in to change notification settings - Fork 3
/
OCLStream.h
80 lines (61 loc) · 2.13 KB
/
OCLStream.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// 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 <sstream>
#include <stdexcept>
#define CL_HPP_ENABLE_EXCEPTIONS
#define CL_HPP_TARGET_OPENCL_VERSION 120
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
#include "CL/cl2.hpp"
#include "Stream.h"
#define IMPLEMENTATION_STRING "OpenCL"
template <class T>
class OCLStream : public Stream<T>
{
protected:
// Size of arrays
const unsigned int array_size;
unsigned int elts_per_lane;
unsigned int chunks_per_wg;
const bool evt_timing;
// Host array for partial sums for dot kernel
std::vector<T> sums;
// Device side pointers to arrays
cl::Buffer d_a;
cl::Buffer d_b;
cl::Buffer d_c;
cl::Buffer d_sum;
// OpenCL objects
cl::Device device;
cl::Context context;
cl::CommandQueue queue;
cl::KernelFunctor<cl::Buffer, cl::Buffer, cl::Buffer, T, T, T> *init_kernel;
cl::KernelFunctor<cl::Buffer, cl::Buffer> *read_kernel;
cl::KernelFunctor<cl::Buffer> *write_kernel;
cl::KernelFunctor<cl::Buffer, cl::Buffer> *copy_kernel;
cl::KernelFunctor<cl::Buffer, cl::Buffer> * mul_kernel;
cl::KernelFunctor<cl::Buffer, cl::Buffer, cl::Buffer> *add_kernel;
cl::KernelFunctor<cl::Buffer, cl::Buffer, cl::Buffer> *triad_kernel;
cl::KernelFunctor<cl::Buffer, cl::Buffer, cl::Buffer, cl::LocalSpaceArg, cl_int> *dot_kernel;
// NDRange configuration for the dot kernel
size_t dot_num_groups;
size_t dot_wgsize;
public:
OCLStream(const unsigned int, const bool, const int);
~OCLStream();
virtual float read() override;
virtual float write() override;
virtual float copy() override;
virtual float add() override;
virtual float mul() override;
virtual float 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;
};
// Populate the devices list
void getDeviceList(void);