1
// This file is part of BOINC.
2
// http://boinc.berkeley.edu
3
// Copyright (C) 2008 University of California
5
// BOINC is free software; you can redistribute it and/or modify it
6
// under the terms of the GNU Lesser General Public License
7
// as published by the Free Software Foundation,
8
// either version 3 of the License, or (at your option) any later version.
10
// BOINC is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
// See the GNU Lesser General Public License for more details.
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
18
// See http://boinc.berkeley.edu/trac/wiki/GPUApp for any compiling issues.
19
// Contributor: Tuan Le (tuanle86@berkeley.edu)
34
#define INPUT_FILENAME "input"
35
#define OUTPUT_FILENAME "output"
36
#define KERNELS_FILENAME "nvopencl_kernels.cl"
37
#define KERNELS_FILEPATH "../../nvopencl_kernels.cl" // for Linux and Mac
38
#define CHECKPOINT_FILE "matrix_inversion_state"
40
#define LOCAL_WORK_SIZE 1
41
#define GLOBAL_WORK_SIZE 400
42
#define MATRIX_SIZE 10
43
#define NUM_ITERATIONS 501 // execute the kernel NUM_ITERATIONS times
46
#include "boinc_win.h"
61
#include "boinc_api.h"
63
#include "graphics2.h"
71
// graphics app sets this to 5 repeatedly,
72
// main program decrements it once/sec.
73
// If it's zero, don't bother updating shmem
82
bool run_slow = false;
83
bool early_exit = false;
84
bool early_crash = false;
85
bool early_sleep = false;
86
double cpu_time = 20, comp_result;
87
bool isStateFileInUse = false;
90
size_t globalThreads[1]; // 1D var for Total # of work items
91
size_t localThreads[1]; // 1D var for # of work items in the work group
94
* Input data is stored here.
99
* Output data is stored here.
103
/* problem size for a 2D matrix. */
104
// Note: we will handle the problem as a 1D matrix.
108
/* The memory buffer that is used as input/output for OpenCL kernel */
109
cl_mem inputBuffer; //in this sample app, we will read the result
110
//from the device back to host from inputBuffer as well.
112
cl_device_id *devices;
113
cl_command_queue commandQueue;
117
/* This program uses three kernels */
118
cl_kernel GEStep1A_kernel;
119
cl_kernel GEStep2_kernel;
120
cl_kernel GEStep3_kernel;
122
/*** FUNCTION DECLARATIONS ***/
125
* Create an input file filled with random data of type cl_float.
127
void generate_random_input_file(int n);
130
* Parse the input file and determine the size of the matrix.
131
* This is an nxn matrix. Note: if width<> height, the matrix is
134
int get_matrix_size(FILE *infile);
137
* Read the float values from input file into "input" array.
139
void fetch_elements_into_host_memory(FILE *infile, cl_float *input);
145
/* Do a billion floating-point ops */
146
static double do_a_giga_flop(int foo);
148
/* Save the computation state into checkpoint file */
149
int do_checkpoint(MFILE& mf, int n, cl_float *input, int matrixSize);
152
void update_shmem() {
155
// always do this; otherwise a graphics app will immediately
156
// assume we're not alive
157
shmem->update_time = dtime();
159
// Check whether a graphics app is running,
160
// and don't bother updating shmem if so.
161
// This doesn't matter here,
162
// but may be worth doing if updating shmem is expensive.
164
if (shmem->countdown > 0) {
165
// the graphics app sets this to 5 every time it renders a frame
170
shmem->fraction_done = boinc_get_fraction_done();
171
shmem->cpu_time = boinc_worker_thread_cpu_time();;
172
boinc_get_status(&shmem->status);
177
* OpenCL related initialisations are done here.
178
* Context, Device list, Command Queue are set up.
179
* Calls are made to set up OpenCL memory buffers that this program uses
180
* and to load the programs into memory and get kernel handles.
182
int initialize_cl(void);
184
int initialize_host(FILE *infile);
187
* Read the file which contains kernel definitions, and stores the file content
188
* into a char array which is used as an argument to clCreateProgramWithSource.
190
char *convert_to_string(const char * filename);
193
* This is called once the OpenCL context, memory etc. are set up,
194
* the program is loaded into memory and the kernel handles are ready.
196
* It sets the values for kernels' arguments and enqueues calls to the kernels
197
* on to the command queue and waits till the calls have finished execution.
199
* It also gets kernel start and end time if profiling is enabled.
201
int run_cl_kernels(void);
203
/* Releases OpenCL resources (Context, Memory etc.) */
204
int cleanup_cl(void);
206
/* Releases program's resources */
207
void cleanup_host(void);
209
/* Write the result to output file */
210
void print_to_file(MFILE *out, float *h_odata, int n);
213
* Functions used to inverst matrix. Call kernels inside.
215
void invert(cl_float * input,
219
void invertge(cl_float * AI_d,
223
#endif /* #ifndef NVOPENCL_H_ */
b'\\ No newline at end of file'