PIPS
Params.h
Go to the documentation of this file.
1 /* ============================================================
2 
3 Copyright (c) 2009 Advanced Micro Devices, Inc. All rights reserved.
4 
5 Redistribution and use of this material is permitted under the following
6 conditions:
7 
8 Redistributions must retain the above copyright notice and all terms of this
9 license.
10 
11 In no event shall anyone redistributing or accessing or using this material
12 commence or participate in any arbitration or legal action relating to this
13 material against Advanced Micro Devices, Inc. or any copyright holders or
14 contributors. The foregoing shall survive any expiration or termination of
15 this license or any agreement or access or use related to this material.
16 
17 ANY BREACH OF ANY TERM OF THIS LICENSE SHALL RESULT IN THE IMMEDIATE REVOCATION
18 OF ALL RIGHTS TO REDISTRIBUTE, ACCESS OR USE THIS MATERIAL.
19 
20 THIS MATERIAL IS PROVIDED BY ADVANCED MICRO DEVICES, INC. AND ANY COPYRIGHT
21 HOLDERS AND CONTRIBUTORS "AS IS" IN ITS CURRENT CONDITION AND WITHOUT ANY
22 REPRESENTATIONS, GUARANTEE, OR WARRANTY OF ANY KIND OR IN ANY WAY RELATED TO
23 SUPPORT, INDEMNITY, ERROR FREE OR UNINTERRUPTED OPERA TION, OR THAT IT IS FREE
24 FROM DEFECTS OR VIRUSES. ALL OBLIGATIONS ARE HEREBY DISCLAIMED - WHETHER
25 EXPRESS, IMPLIED, OR STATUTORY - INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED
26 WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
27 ACCURACY, COMPLETENESS, OPERABILITY, QUALITY OF SERVICE, OR NON-INFRINGEMENT.
28 IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. OR ANY COPYRIGHT HOLDERS OR
29 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE,
30 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
31 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, REVENUE, DATA, OR PROFITS; OR
32 BUSINESS INTERRUPTION) HOWEVER CAUSED OR BASED ON ANY THEORY OF LIABILITY
33 ARISING IN ANY WAY RELATED TO THIS MATERIAL, EVEN IF ADVISED OF THE POSSIBILITY
34 OF SUCH DAMAGE. THE ENTIRE AND AGGREGATE LIABILITY OF ADVANCED MICRO DEVICES,
35 INC. AND ANY COPYRIGHT HOLDERS AND CONTRIBUTORS SHALL NOT EXCEED TEN DOLLARS
36 (US $10.00). ANYONE REDISTRIBUTING OR ACCESSING OR USING THIS MATERIAL ACCEPTS
37 THIS ALLOCATION OF RISK AND AGREES TO RELEASE ADVANCED MICRO DEVICES, INC. AND
38 ANY COPYRIGHT HOLDERS AND CONTRIBUTORS FROM ANY AND ALL LIABILITIES,
39 OBLIGATIONS, CLAIMS, OR DEMANDS IN EXCESS OF TEN DOLLARS (US $10.00). THE
40 FOREGOING ARE ESSENTIAL TERMS OF THIS LICENSE AND, IF ANY OF THESE TERMS ARE
41 CONSTRUED AS UNENFORCEABLE, FAIL IN ESSENTIAL PURPOSE, OR BECOME VOID OR
42 DETRIMENTAL TO ADVANCED MICRO DEVICES, INC. OR ANY COPYRIGHT HOLDERS OR
43 CONTRIBUTORS FOR ANY REASON, THEN ALL RIGHTS TO REDISTRIBUTE, ACCESS OR USE
44 THIS MATERIAL SHALL TERMINATE IMMEDIATELY. MOREOVER, THE FOREGOING SHALL
45 SURVIVE ANY EXPIRATION OR TERMINATION OF THIS LICENSE OR ANY AGREEMENT OR
46 ACCESS OR USE RELATED TO THIS MATERIAL.
47 
48 NOTICE IS HEREBY PROVIDED, AND BY REDISTRIBUTING OR ACCESSING OR USING THIS
49 MATERIAL SUCH NOTICE IS ACKNOWLEDGED, THAT THIS MATERIAL MAY BE SUBJECT TO
50 RESTRICTIONS UNDER THE LAWS AND REGULATIONS OF THE UNITED STATES OR OTHER
51 COUNTRIES, WHICH INCLUDE BUT ARE NOT LIMITED TO, U.S. EXPORT CONTROL LAWS SUCH
52 AS THE EXPORT ADMINISTRATION REGULATIONS AND NATIONAL SECURITY CONTROLS AS
53 DEFINED THEREUNDER, AS WELL AS STATE DEPARTMENT CONTROLS UNDER THE U.S.
54 MUNITIONS LIST. THIS MATERIAL MAY NOT BE USED, RELEASED, TRANSFERRED, IMPORTED,
55 EXPORTED AND/OR RE-EXPORTED IN ANY MANNER PROHIBITED UNDER ANY APPLICABLE LAWS,
56 INCLUDING U.S. EXPORT CONTROL LAWS REGARDING SPECIFICALLY DESIGNATED PERSONS,
57 COUNTRIES AND NATIONALS OF COUNTRIES SUBJECT TO NATIONAL SECURITY CONTROLS.
58 MOREOVER, THE FOREGOING SHALL SURVIVE ANY EXPIRATION OR TERMINATION OF ANY
59 LICENSE OR AGREEMENT OR ACCESS OR USE RELATED TO THIS MATERIAL.
60 
61 NOTICE REGARDING THE U.S. GOVERNMENT AND DOD AGENCIES: This material is
62 provided with "RESTRICTED RIGHTS" and/or "LIMITED RIGHTS" as applicable to
63 computer software and technical data, respectively. Use, duplication,
64 distribution or disclosure by the U.S. Government and/or DOD agencies is
65 subject to the full extent of restrictions in all applicable regulations,
66 including those found at FAR52.227 and DFARS252.227 et seq. and any successor
67 regulations thereof. Use of this material by the U.S. Government and/or DOD
68 agencies is acknowledgment of the proprietary rights of any copyright holders
69 and contributors, including those of Advanced Micro Devices, Inc., as well as
70 the provisions of FAR52.227-14 through 23 regarding privately developed and/or
71 commercial computer software.
72 
73 This license forms the entire agreement regarding the subject matter hereof and
74 supersedes all proposals and prior discussions and writings between the parties
75 with respect thereto. This license does not affect any ownership, rights, title,
76 or interest in, or relating to, this material. No terms of this license can be
77 modified or waived, and no breach of this license can be excused, unless done
78 so in a writing signed by all affected parties. Each term of this license is
79 separately enforceable. If any term of this license is determined to be or
80 becomes unenforceable or illegal, such term shall be reformed to the minimum
81 extent necessary in order for this license to remain in effect in accordance
82 with its terms as modified by such reformation. This license shall be governed
83 by and construed in accordance with the laws of the State of Texas without
84 regard to rules on conflicts of law of any state or jurisdiction or the United
85 Nations Convention on the International Sale of Goods. All disputes arising out
86 of this license shall be subject to the jurisdiction of the federal and state
87 courts in Austin, Texas, and all defenses are hereby waived concerning personal
88 jurisdiction and venue of these courts.
89 
90 ============================================================ */
91 
92 
93 #ifndef PARAMS_H_
94 #define PARAMS_H_
95 
96 #define DEFAULT_NUM_THREADS 4
97 
99 {
100  int nWidth; //Output image width
101  int nHeight; //Output image height
102  int nInWidth; //Input image width
103  int nInHeight; //Input image height
104  int nFilterWidth; //Filter size is nFilterWidth X nFilterWidth
105  int nIterations; //Run timing loop for nIterations
106 
107  enum {WORK_DIM=2};
108  size_t globalNDWorkSize[WORK_DIM]; //Total number of work items
109  size_t localNDWorkSize[WORK_DIM]; //Work items in each work-group
110 
111  std::string kernelFile; //File that contains all the kernels
112  //Vector to store all kernels
113  std::vector<std::string> kernelNames;
114  int nTotalKernels; //kernelNames.size()
115 
116  //Test CPU performance with 1,4,8 etc. OpenMP threads
117  std::vector<int> ompThreads;
118  int nOmpRuns; //ompThreads.size()
119 
120  bool bCPUTiming; //Time CPU performance
121  bool bDeviceKernelTiming; //Time OpenCL performance
122 
123  bool bVerify; //Crosscheck the OpenCL results with the CPU results
125 
126 void Usage(char *name);
127 void ParseCommandLine(int argc, char* argv[]);
128 
129 void InitParams(int argc, char* argv[])
130 {
131  params.nWidth = 1024*8;
132  params.nHeight = 1024*8;
133  params.nFilterWidth = 50;
134  params.nIterations = 3;
135 
136  params.bCPUTiming = true;
138  params.bVerify = true;
139 
140  params.kernelFile = "convol.cl";
141  ParseCommandLine(argc, argv);
142 
145 
148  params.localNDWorkSize[0] = 32;
149  params.localNDWorkSize[1] = 32;
150 
151  params.kernelNames.push_back("Convolve");
153 
154  params.ompThreads.push_back(4);
155  //params.ompThreads.push_back(1);
156  //params.ompThreads.push_back(8);
157  params.nOmpRuns = params.ompThreads.size();
158 
160  params.bVerify = false;
161 }
162 
163 void ParseCommandLine(int argc, char* argv[])
164 {
165  for (int i = 1; i < argc; ++i)
166  {
167  switch (argv[i][1])
168  {
169  case 'c':
170  params.bCPUTiming = false;
171  break;
172  case 'k':
173  params.bDeviceKernelTiming = false;
174  break;
175  case 'e':
176  params.bVerify = false;
177  break;
178  case 'f':
179  if (++i < argc)
180  {
181  sscanf(argv[i], "%u", &params.nFilterWidth);
182  }
183  else
184  {
185  std::cerr << "Could not read argument after option " << argv[i-1] << std::endl;
186  Usage(argv[0]);
187  throw;
188  }
189  break;
190  case 'i':
191  if (++i < argc)
192  {
193  sscanf(argv[i], "%u", &params.nIterations);
194  }
195  else
196  {
197  std::cerr << "Could not read argument after option " << argv[i-1] << std::endl;
198  Usage(argv[0]);
199  throw;
200  }
201  break;
202  case 'x':
203  if (++i < argc)
204  {
205  sscanf(argv[i], "%u", &params.nWidth);
206  }
207  else
208  {
209  std::cerr << "Could not read argument after option " << argv[i-1] << std::endl;
210  Usage(argv[0]);
211  throw;
212  }
213  break;
214  case 'y':
215  if (++i < argc)
216  {
217  sscanf(argv[i], "%u", &params.nHeight);
218  }
219  else
220  {
221  std::cerr << "Could not read argument after option " << argv[i-1] << std::endl;
222  Usage(argv[0]);
223  throw;
224  }
225  break;
226  case 'o':
227  if (++i < argc)
228  {
229  params.kernelFile = argv[i];
230  }
231  else
232  {
233  std::cerr << "Could not read argument after option " << argv[i-1] << std::endl;
234  Usage(argv[0]);
235  throw;
236  }
237  break;
238  case 'h':
239  Usage(argv[0]);
240  exit(1);
241  default:
242  std::cerr << "Invalid argument " << argv[i] << std::endl;
243  Usage(argv[0]);
244  throw(std::string("Invalid argument"));
245  }
246  }
247 }
248 
249 void Usage(char *name)
250 {
251  printf("\tUsage: %s [-h] [-c] [-k] [-e] [-f <int>] [-i <int>] [-x <int>] [-y <int>] [-o kernel]\n", name);
252  printf(" -h Print this help menu.\n");
253  printf(" -c Supress CPU timing run.\n");
254  printf(" -k Supress Device (kernel only) timing run.\n");
255  printf(" -e Supress output verification.\n");
256  printf(" -f <int> Sets the filter width.\n");
257  printf(" -i <int> Number of iterations.\n");
258  printf(" -x <int> Sets the image width.\n");
259  printf(" -y <int> Sets the image height.\n");
260  printf(" -o <kernel> Sets the OpenCL kernel to use.\n");
261 }
262 
263 
264 #endif //#ifndef PARAMS_H_
struct paramStruct params
void InitParams(int argc, char *argv[])
Definition: Params.h:129
void Usage(char *name)
Definition: Params.h:249
void ParseCommandLine(int argc, char *argv[])
Definition: Params.h:163
#define exit(code)
Definition: misc-local.h:54
char * string
STRING.
Definition: newgen_types.h:39
int printf()
int nTotalKernels
Definition: Params.h:114
int nInWidth
Definition: Params.h:102
std::string kernelFile
Definition: Params.h:111
int nWidth
Definition: Params.h:100
bool bCPUTiming
Definition: Params.h:120
bool bVerify
Definition: Params.h:123
std::vector< std::string > kernelNames
Definition: Params.h:113
@ WORK_DIM
Definition: Params.h:107
int nInHeight
Definition: Params.h:103
size_t globalNDWorkSize[WORK_DIM]
Definition: Params.h:108
std::vector< int > ompThreads
Definition: Params.h:117
int nHeight
Definition: Params.h:101
bool bDeviceKernelTiming
Definition: Params.h:121
int nOmpRuns
Definition: Params.h:118
size_t localNDWorkSize[WORK_DIM]
Definition: Params.h:109
int nIterations
Definition: Params.h:105
int nFilterWidth
Definition: Params.h:104