~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to samples/nvcuda/cuda.h

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This file is part of BOINC.
 
2
// http://boinc.berkeley.edu
 
3
// Copyright (C) 2008 University of California
 
4
//
 
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.
 
9
//
 
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.
 
14
//
 
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/>.
 
17
//
 
18
// See http://boinc.berkeley.edu/trac/wiki/GPUApp for any compiling issues
 
19
// Contributor: Tuan Le (tuanle86@berkeley.edu)
 
20
 
 
21
#ifndef CUDA_H_
 
22
#define CUDA_H_
 
23
 
 
24
#ifdef _WIN32
 
25
#include "boinc_win.h"
 
26
#else
 
27
#include "config.h"
 
28
#include <cstdio>
 
29
#include <cctype>
 
30
#include <ctime>
 
31
#include <cstring>
 
32
#include <cstdlib>
 
33
#include <csignal>
 
34
#include <unistd.h>
 
35
#endif
 
36
 
 
37
#include "str_util.h"
 
38
#include "util.h"
 
39
#include "filesys.h"
 
40
#include "boinc_api.h"
 
41
#include "mfile.h"
 
42
#include "graphics2.h"
 
43
#include "cuda_config.h"
 
44
 
 
45
#define CHECKPOINT_FILE "matrix_inversion_state"
 
46
#define INPUT_FILENAME "input"
 
47
#define OUTPUT_FILENAME "output"
 
48
#define MATRIX_SIZE 10
 
49
#define NUM_ITERATIONS 501 // execute the kernel NUM_ITERATIONS times
 
50
 
 
51
struct UC_SHMEM {
 
52
    double update_time;
 
53
    double fraction_done;
 
54
    double cpu_time;
 
55
    BOINC_STATUS status;
 
56
    int countdown;
 
57
    // graphics app sets this to 5 repeatedly,
 
58
    // main program decrements it once/sec.
 
59
    // If it's zero, don't bother updating shmem
 
60
};
 
61
 
 
62
/*** BOINC FUNCTION DECLARATIONS  ***/
 
63
 
 
64
/* Do a billion floating-point ops */
 
65
static double do_a_giga_flop(int foo);
 
66
 
 
67
/* Save the computation state into checkpoint file */
 
68
int do_checkpoint(MFILE& mf, int n, REAL *h_idata, int dimension);
 
69
 
 
70
#ifdef APP_GRAPHICS
 
71
void update_shmem() {
 
72
    if (!shmem) return;
 
73
        
 
74
    // always do this; otherwise a graphics app will immediately
 
75
    // assume we're not alive
 
76
    shmem->update_time = dtime();
 
77
        
 
78
    // Check whether a graphics app is running,
 
79
    // and don't bother updating shmem if so.
 
80
    // This doesn't matter here,
 
81
    // but may be worth doing if updating shmem is expensive.
 
82
    //
 
83
    if (shmem->countdown > 0) {
 
84
        // the graphics app sets this to 5 every time it renders a frame
 
85
        shmem->countdown--;
 
86
    } else {
 
87
        return;
 
88
    }
 
89
    shmem->fraction_done = boinc_get_fraction_done();
 
90
    shmem->cpu_time = boinc_worker_thread_cpu_time();;
 
91
    boinc_get_status(&shmem->status);
 
92
}
 
93
#endif
 
94
 
 
95
/*** FUNCTION DECLARATIONS ***/
 
96
 
 
97
/*
 
98
 * Parse the input file and determine the size of the matrix.
 
99
 * This is an nxn matrix. Note: if width <> height, the matrix is
 
100
 * non-invertible.
 
101
 */
 
102
int get_matrix_dimension(FILE *infile);
 
103
 
 
104
/* Create an input file filled with random data of type cl_float. */
 
105
void generate_random_input_file(int n);
 
106
 
 
107
/* Read the REAL values from input file into host array. */
 
108
void fetch_elements_into_host_memory(FILE *infile, REAL *h_idata);
 
109
 
 
110
/* Write the result to output file */
 
111
void print_to_file(MFILE *out, float *h_odata, int dimension);
 
112
 
 
113
/* invert the given matrix A */
 
114
extern void invert(REAL * A, int n);
 
115
 
 
116
#endif  /* #ifndef CUDA_H_ */
 
 
b'\\ No newline at end of file'