svn path=/trunk/boinc/; revision=21750

This commit is contained in:
Tuan Le 2010-06-15 18:09:28 +00:00
parent 9194af6722
commit 7c87348f52
3 changed files with 1035 additions and 658 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,132 +1,86 @@
/* ============================================================
Copyright (c) 2009 Advanced Micro Devices, Inc. All rights reserved.
Redistribution and use of this material is permitted under the following
conditions:
Redistributions must retain the above copyright notice and all terms of this
license.
In no event shall anyone redistributing or accessing or using this material
commence or participate in any arbitration or legal action relating to this
material against Advanced Micro Devices, Inc. or any copyright holders or
contributors. The foregoing shall survive any expiration or termination of
this license or any agreement or access or use related to this material.
ANY BREACH OF ANY TERM OF THIS LICENSE SHALL RESULT IN THE IMMEDIATE REVOCATION
OF ALL RIGHTS TO REDISTRIBUTE, ACCESS OR USE THIS MATERIAL.
THIS MATERIAL IS PROVIDED BY ADVANCED MICRO DEVICES, INC. AND ANY COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" IN ITS CURRENT CONDITION AND WITHOUT ANY
REPRESENTATIONS, GUARANTEE, OR WARRANTY OF ANY KIND OR IN ANY WAY RELATED TO
SUPPORT, INDEMNITY, ERROR FREE OR UNINTERRUPTED OPERA TION, OR THAT IT IS FREE
FROM DEFECTS OR VIRUSES. ALL OBLIGATIONS ARE HEREBY DISCLAIMED - WHETHER
EXPRESS, IMPLIED, OR STATUTORY - INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
ACCURACY, COMPLETENESS, OPERABILITY, QUALITY OF SERVICE, OR NON-INFRINGEMENT.
IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. OR ANY COPYRIGHT HOLDERS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, REVENUE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED OR BASED ON ANY THEORY OF LIABILITY
ARISING IN ANY WAY RELATED TO THIS MATERIAL, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE. THE ENTIRE AND AGGREGATE LIABILITY OF ADVANCED MICRO DEVICES,
INC. AND ANY COPYRIGHT HOLDERS AND CONTRIBUTORS SHALL NOT EXCEED TEN DOLLARS
(US $10.00). ANYONE REDISTRIBUTING OR ACCESSING OR USING THIS MATERIAL ACCEPTS
THIS ALLOCATION OF RISK AND AGREES TO RELEASE ADVANCED MICRO DEVICES, INC. AND
ANY COPYRIGHT HOLDERS AND CONTRIBUTORS FROM ANY AND ALL LIABILITIES,
OBLIGATIONS, CLAIMS, OR DEMANDS IN EXCESS OF TEN DOLLARS (US $10.00). THE
FOREGOING ARE ESSENTIAL TERMS OF THIS LICENSE AND, IF ANY OF THESE TERMS ARE
CONSTRUED AS UNENFORCEABLE, FAIL IN ESSENTIAL PURPOSE, OR BECOME VOID OR
DETRIMENTAL TO ADVANCED MICRO DEVICES, INC. OR ANY COPYRIGHT HOLDERS OR
CONTRIBUTORS FOR ANY REASON, THEN ALL RIGHTS TO REDISTRIBUTE, ACCESS OR USE
THIS MATERIAL SHALL TERMINATE IMMEDIATELY. MOREOVER, THE FOREGOING SHALL
SURVIVE ANY EXPIRATION OR TERMINATION OF THIS LICENSE OR ANY AGREEMENT OR
ACCESS OR USE RELATED TO THIS MATERIAL.
NOTICE IS HEREBY PROVIDED, AND BY REDISTRIBUTING OR ACCESSING OR USING THIS
MATERIAL SUCH NOTICE IS ACKNOWLEDGED, THAT THIS MATERIAL MAY BE SUBJECT TO
RESTRICTIONS UNDER THE LAWS AND REGULATIONS OF THE UNITED STATES OR OTHER
COUNTRIES, WHICH INCLUDE BUT ARE NOT LIMITED TO, U.S. EXPORT CONTROL LAWS SUCH
AS THE EXPORT ADMINISTRATION REGULATIONS AND NATIONAL SECURITY CONTROLS AS
DEFINED THEREUNDER, AS WELL AS STATE DEPARTMENT CONTROLS UNDER THE U.S.
MUNITIONS LIST. THIS MATERIAL MAY NOT BE USED, RELEASED, TRANSFERRED, IMPORTED,
EXPORTED AND/OR RE-EXPORTED IN ANY MANNER PROHIBITED UNDER ANY APPLICABLE LAWS,
INCLUDING U.S. EXPORT CONTROL LAWS REGARDING SPECIFICALLY DESIGNATED PERSONS,
COUNTRIES AND NATIONALS OF COUNTRIES SUBJECT TO NATIONAL SECURITY CONTROLS.
MOREOVER, THE FOREGOING SHALL SURVIVE ANY EXPIRATION OR TERMINATION OF ANY
LICENSE OR AGREEMENT OR ACCESS OR USE RELATED TO THIS MATERIAL.
NOTICE REGARDING THE U.S. GOVERNMENT AND DOD AGENCIES: This material is
provided with "RESTRICTED RIGHTS" and/or "LIMITED RIGHTS" as applicable to
computer software and technical data, respectively. Use, duplication,
distribution or disclosure by the U.S. Government and/or DOD agencies is
subject to the full extent of restrictions in all applicable regulations,
including those found at FAR52.227 and DFARS252.227 et seq. and any successor
regulations thereof. Use of this material by the U.S. Government and/or DOD
agencies is acknowledgment of the proprietary rights of any copyright holders
and contributors, including those of Advanced Micro Devices, Inc., as well as
the provisions of FAR52.227-14 through 23 regarding privately developed and/or
commercial computer software.
This license forms the entire agreement regarding the subject matter hereof and
supersedes all proposals and prior discussions and writings between the parties
with respect thereto. This license does not affect any ownership, rights, title,
or interest in, or relating to, this material. No terms of this license can be
modified or waived, and no breach of this license can be excused, unless done
so in a writing signed by all affected parties. Each term of this license is
separately enforceable. If any term of this license is determined to be or
becomes unenforceable or illegal, such term shall be reformed to the minimum
extent necessary in order for this license to remain in effect in accordance
with its terms as modified by such reformation. This license shall be governed
by and construed in accordance with the laws of the State of Texas without
regard to rules on conflicts of law of any state or jurisdiction or the United
Nations Convention on the International Sale of Goods. All disputes arising out
of this license shall be subject to the jurisdiction of the federal and state
courts in Austin, Texas, and all defenses are hereby waived concerning personal
jurisdiction and venue of these courts.
============================================================ */
#ifndef TEMPLATE_H_
#define TEMPLATE_H_
/*
* atiopencl.hpp
* Author: Tuan Le
* Date: 06/14/2010
* University of California, Berkeley
* tuanle86@berkeley.edu
*/
#ifndef ATIOPENCL_H_
#define ATIOPENCL_H_
#include <CL/cl.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#define INPUT_FILENAME "input"
#define OUTPUT_FILENAME "output"
#define KERNELS_FILENAME "atiopencl_kernels.cl"
#define KERNELS_FILEPATH "../samples/atiopencl/atiopencl_kernels.cl"
#define CHECKPOINT_FILE "matrix_inversion_state"
#define MATRIX_SIZE 20
#define NUM_ITERATIONS 50 // execute the kernel NUM_ITERATIONS times
#ifdef _WIN32
#include "boinc_win.h"
#else
#include "config.h"
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <csignal>
#include <unistd.h>
#endif
//#include <cuda_runtime.h>
//#include <cublas.h>
#include "str_util.h"
#include "util.h"
#include "filesys.h"
#include "boinc_api.h"
#include "mfile.h"
#include "graphics2.h"
#ifdef APP_GRAPHICS
#include "uc2.h"
UC_SHMEM* shmem;
#endif
/*** GLOBALS ***/
bool run_slow = false;
bool early_exit = false;
bool early_crash = false;
bool early_sleep = false;
double cpu_time = 20, comp_result;
bool isStateFileInUse = false;
const char *source;
/*
* Input data is stored here.
*/
cl_uint *input;
cl_float *input;
/*
* Output data is stored here.
*/
cl_uint *output;
cl_float *output;
/*
* Multiplier is stored in this variable
*/
cl_uint multiplier;
/* problem size for 1D algorithm and width of problem size for 2D algorithm */
/* problem size for a 2D matrix. */
// Note: we will handle the problem as a 1D matrix.
cl_uint width;
cl_uint height;
/* The memory buffer that is used as input/output for OpenCL kernel */
cl_mem inputBuffer;
cl_mem outputBuffer;
cl_mem inputBuffer; //in this sample app, we will read the result from the device back to host from inputBuffer as well.
cl_context context;
cl_device_id *devices;
@ -134,11 +88,37 @@ cl_command_queue commandQueue;
cl_program program;
/* This program uses only one kernel and this serves as a handle to it */
cl_kernel kernel;
/* This program uses three kernels */
cl_kernel GEStep1A_kernel;
cl_kernel GEStep2_kernel;
cl_kernel GEStep3_kernel;
/*** FUNCTION DECLARATIONS ***/
/*
* Create an input file filled with random data of type cl_float.
*/
void generateRandomInputFile(int n);
/*
* Parse the input file and determine the size of the matrix.
* This is an nxn matrix. Note: if width<> height, the matrix is
* non-invertible.
*/
int getMatrixSize(FILE *infile);
/*
* Read the float values from input file into "input" array.
*/
void fetchElementsIntoHostMemory(FILE *infile, cl_float *input);
/*
* BOINC functions
*/
static double do_a_giga_flop(int foo);
int do_checkpoint(MFILE& mf, int n, cl_float *input, int matrixSize);
void update_shmem();
/*
* OpenCL related initialisations are done here.
* Context, Device list, Command Queue are set up.
@ -147,10 +127,13 @@ cl_kernel kernel;
*/
int initializeCL(void);
int initializeHost(FILE *infile);
/*
*
* Read the file which contains kernel definitions, and stores the file content
* into a char array which is used as an argument to clCreateProgramWithSource.
*/
std::string convertToString(const char * filename);
char *convertToString(const char * filename);
/*
* This is called once the OpenCL context, memory etc. are set up,
@ -169,16 +152,24 @@ int cleanupCL(void);
/* Releases program's resources */
void cleanupHost(void);
/* Write the result to output file */
void printToFile(MFILE *out, float *h_odata, int n);
/*
* Prints no more than 256 elements of the given array.
* Prints full array if length is less than 256.
*
* Prints Array name followed by elements.
* Check if the device is able to support the requested number of work items.
*/
void print1DArray(
const std::string arrayName,
const unsigned int * arrayData,
const unsigned int length);
int checkDeviceCapability(size_t *globalThreads,
size_t *localThreads);
/*
* Functions used to inverst matrix. Call kernels inside.
*/
void invert(cl_float * input,
cl_float *output,
int n);
#endif /* #ifndef TEMPLATE_H_ */
void invertge(cl_float * AI_d,
int lda,
int n);
#endif /* #ifndef ATIOPENCL_H_ */

View File

@ -1,14 +1,36 @@
/*!
* Sample kernel which multiplies every element of the input array with
* a constant and stores it at the corresponding output array
/*
* atiopencl_kernels.cl
* Author: Tuan Le
* Date: 06/14/2010
* University of California, Berkeley
* tuanle86@berkeley.edu
*/
__kernel void templateKernel(__global unsigned int * output,
__global unsigned int * input,
const unsigned int multiplier)
{
uint tid = get_global_id(0);
output[tid] = input[tid] * multiplier;
__kernel void GEStep1A(__global float * AI, int i, int n2, int lda2) {
//int k = get_group_id(0) * get_local_size(0) + get_local_id(0);
int k=get_global_id(0);
if (k>i && k < n2 && AI[i*lda2+k]!=0) {
float multiplyer = -AI[i*lda2+k]/AI[i*lda2+i];
int n = n2 / 2;
for (int j = i+1; j < n; j++) {
AI[j*lda2+k] += multiplyer*AI[j*lda2+i];
}
}
}
__kernel void GEStep2(__global float * AI,float diag,int i, int n2, int lda2) {
int k = get_global_id(0);
if (k < n2) {
AI[i*lda2+k] /= diag;
}
}
__kernel void GEStep3(__global float * AI,int i, int n2, int lda2) {
int k = get_global_id(0);
if (k > i && k < n2) {
float multiplyer = -AI[i*lda2+k];
for (int j = 0; j < i; j++) {
AI[j*lda2+k] += multiplyer*AI[j*lda2+i];
}
}
}