1
- // /////////////////////////////////////////////////////////////////////////////
1
+ // /////////////////////////////////////////////////////////////////////////////
2
2
/*
3
- * Copyright (c) 2017 , Intel Corporation
3
+ * Copyright (c) 2019 , Intel Corporation
4
4
*
5
5
* Permission is hereby granted, free of charge, to any person obtaining a
6
6
* copy of this software and associated documentation files (the
12
12
*
13
13
* The above copyright notice and this permission notice shall be included
14
14
* in all copies or substantial portions of the Software.
15
- *
15
+ *
16
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
17
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
18
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
19
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
20
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
21
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
- */
23
+ */
24
24
// /////////////////////////////////////////////////////////////////////////////
25
25
26
26
#include < iostream>
33
33
#include < bits/stdc++.h>
34
34
35
35
static const int32_t MAJ_VERSION = 1 ;
36
- static const int32_t MIN_VERSION = 0 ;
36
+ static const int32_t MIN_VERSION = 1 ;
37
37
static const char *HEADER_EXT = " .h" ;
38
38
static const char *SOURCE_EXT = " .c" ;
39
39
static const char *PARAM_I = " -i" ;
40
40
static const char *PARAM_O = " -o" ;
41
41
static const char *PARAM_V = " -v" ;
42
+ static const char *PARAM_INDEX = " -index" ;
43
+ static const char *PARAM_TOTAL = " -t" ;
44
+
42
45
#ifdef LINUX_
43
46
static const char *FILE_SEP = " /" ;
44
47
#else
45
48
static const char *FILE_SEP = " \\ " ;
46
49
#endif
47
50
48
51
static const char *COPYRIGHT =
49
- " /* \n "
50
- " * Copyright (c) 2019, Intel Corporation \n "
51
- " * \n "
52
- " * Permission is hereby granted, free of charge, to any person obtaining a \n "
53
- " * copy of this software and associated documentation files (the \n "
54
- " * 'Software'), to deal in the Software without restriction, including \n "
55
- " * without limitation the rights to use, copy, modify, merge, publish, \n "
56
- " * distribute, sublicense, and/or sell copies of the Software, and to \n "
57
- " * permit persons to whom the Software is furnished to do so, subject to \n "
58
- " * the following conditions: \n "
59
- " * \n "
60
- " * The above copyright notice and this permission notice shall be included \n "
61
- " * in all copies or substantial portions of the Software. \n "
62
- " * \n "
63
- " * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS \n "
64
- " * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF \n "
65
- " * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. \n "
66
- " * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY \n "
67
- " * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, \n "
68
- " * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE \n "
69
- " * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \n "
70
- " */ \n "
71
- " \n "
72
- " //////////////////////////////////////////////////////////////////////////////// \n "
73
- " // !!! WARNING - AUTO GENERATED FILE. DO NOT EDIT DIRECTLY. !!! \n "
74
- " // Generated by KernelBinToSource.exe tool \n "
75
- " //////////////////////////////////////////////////////////////////////////////// \n "
52
+ " /*\n "
53
+ " * Copyright (c) 2019, Intel Corporation\n "
54
+ " *\n "
55
+ " * Permission is hereby granted, free of charge, to any person obtaining a\n "
56
+ " * copy of this software and associated documentation files (the\n "
57
+ " * 'Software'), to deal in the Software without restriction, including\n "
58
+ " * without limitation the rights to use, copy, modify, merge, publish,\n "
59
+ " * distribute, sublicense, and/or sell copies of the Software, and to\n "
60
+ " * permit persons to whom the Software is furnished to do so, subject to\n "
61
+ " * the following conditions:\n "
62
+ " *\n "
63
+ " * The above copyright notice and this permission notice shall be included\n "
64
+ " * in all copies or substantial portions of the Software.\n "
65
+ " *\n "
66
+ " * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS\n "
67
+ " * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n "
68
+ " * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n "
69
+ " * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n "
70
+ " * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n "
71
+ " * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n "
72
+ " * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n "
73
+ " */\n "
74
+ " \n "
75
+ " ////////////////////////////////////////////////////////////////////////////////\n "
76
+ " // !!! WARNING - AUTO GENERATED FILE. DO NOT EDIT DIRECTLY. !!!\n "
77
+ " // Generated by KernelBinToSource.exe tool\n "
78
+ " ////////////////////////////////////////////////////////////////////////////////\n "
76
79
;
77
80
78
81
// -----------------------------------------------------------------------------
@@ -171,6 +174,120 @@ int32_t writeHeaderFile(
171
174
return iStatus;
172
175
}
173
176
177
+ // -----------------------------------------------------------------------------
178
+ // Writes Partial Source file
179
+ // -----------------------------------------------------------------------------
180
+ int32_t writePartialSourceFile (
181
+ const uint32_t *pBuffer,
182
+ uint32_t uiSize,
183
+ const std::string &sFileName ,
184
+ const std::string &sVarName ,
185
+ const uint32_t &index,
186
+ const uint32_t &total)
187
+ {
188
+ int32_t iStatus = -1 ;
189
+ std::ofstream oOutStream;
190
+ std::stringstream oSs;
191
+ std::string sSizeName ;
192
+ std::string sPlatformName ;
193
+ const uint32_t uiHexLen = 11 ;
194
+ char sHex [uiHexLen];
195
+ uint32_t offset_size = 0 ;
196
+ uint32_t final_size = (uiSize + total) * sizeof (uint32_t );
197
+ uint32_t stub = 0 ;
198
+
199
+ oOutStream.open (sFileName .c_str (), std::ios::out | std::ios::trunc );
200
+ if (!oOutStream.is_open ())
201
+ {
202
+ printf (" Error: Unable to open file '%s' for writing\n " , sFileName .c_str ());
203
+ goto finish;
204
+ }
205
+
206
+ sSizeName = " extern const unsigned int " + sVarName + " _SIZE" ;
207
+
208
+ sPlatformName = sVarName ;
209
+ sPlatformName .erase (0 , sPlatformName .find_first_of (' G' ,3 ) + 1 );
210
+
211
+ oSs << COPYRIGHT << std::endl;
212
+ oSs << " #ifdef IGFX_GEN" << sPlatformName .c_str () << " _SUPPORTED" << std::endl;
213
+ oSs << sSizeName .c_str () << " = " << final_size << " ;" << std::endl
214
+ << " extern const unsigned int " << sVarName .c_str () << " [] ="
215
+ << std::endl << " {" ;
216
+
217
+ for (stub = 0 ; stub < total; stub++)
218
+ {
219
+ if (stub % 8 == 0 )
220
+ {
221
+ oSs << std::endl << " " ;
222
+ }
223
+
224
+ if ( stub == index + 1 )
225
+ {
226
+ offset_size = uiSize * sizeof (uint32_t );
227
+ }
228
+
229
+ snprintf (sHex , uiHexLen, " 0x%08x" , offset_size);
230
+
231
+ sHex [uiHexLen - 1 ] = ' \0 ' ;
232
+
233
+ if (stub % 8 == 7 )
234
+ {
235
+ oSs << sHex << " ," ;
236
+ }else
237
+ {
238
+ oSs << sHex << " , " ;
239
+ }
240
+ }
241
+
242
+ for (uint32_t i = 0 ; i < uiSize; i++)
243
+ {
244
+ if ((i + stub) % 8 == 0 )
245
+ {
246
+ oSs << std::endl << " " ;
247
+ }
248
+
249
+ snprintf (sHex , uiHexLen, " 0x%08x" , pBuffer[i]);
250
+ sHex [uiHexLen - 1 ] = ' \0 ' ;
251
+ oSs << sHex ;
252
+
253
+ if (i < (uiSize - 1 ))
254
+ {
255
+ if ((i + stub) % 8 == 7 )
256
+ {
257
+ oSs << " ," ;
258
+ }
259
+ else
260
+ {
261
+ oSs << " , " ;
262
+ }
263
+ }
264
+ }
265
+
266
+ oSs << std::endl << " };" << std::endl;
267
+
268
+ // Dummy kernel filled with 216 bytes
269
+ oSs << " #else" << std::endl
270
+ << sSizeName .c_str () << " = 216;" << std::endl
271
+ << " extern const unsigned int " << sVarName .c_str () << " [] = {" << std::endl
272
+ << " 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000," << std::endl
273
+ << " };" << std::endl
274
+ << " #endif" << std::endl;
275
+
276
+ oOutStream << oSs.rdbuf ();
277
+
278
+ printf (" Source file '%s' generated successfully!\n " , sFileName .c_str ());
279
+
280
+ iStatus = 0 ;
281
+
282
+ finish:
283
+ if (oOutStream.is_open ())
284
+ {
285
+ oOutStream.close ();
286
+ }
287
+
288
+ return iStatus;
289
+ }
290
+
174
291
// -----------------------------------------------------------------------------
175
292
// Writes the Source file
176
293
// -----------------------------------------------------------------------------
@@ -225,6 +342,7 @@ int32_t writeSourceFile(
225
342
}
226
343
oSs << std::endl << " };" << std::endl;
227
344
345
+ // Dummy kernel filled with 216 bytes
228
346
oSs << " #else" << std::endl
229
347
<< sSizeName .c_str () << " = 216;" << std::endl
230
348
<< " extern const unsigned int " << sVarName .c_str () << " [] = {" << std::endl
@@ -253,7 +371,9 @@ int32_t writeSourceFile(
253
371
int32_t createSourceFile (
254
372
const std::string &sInputFile ,
255
373
const std::string &sOutputDir ,
256
- const std::string &sVar )
374
+ const std::string &sVar ,
375
+ const uint32_t &index,
376
+ const uint32_t &total)
257
377
{
258
378
struct stat StatResult;
259
379
int32_t iStatus = -1 ;
@@ -316,7 +436,7 @@ int32_t createSourceFile(
316
436
pBuffer = new uint32_t [uiIntSize];
317
437
pBuffer[uiIntSize - 1 ] = 0 ; // set the last entry as 0 for handling non uint32_t file sizes.
318
438
oInStream.read (reinterpret_cast <char *>(pBuffer), uiSize);
319
-
439
+
320
440
if (oInStream.bad ())
321
441
{
322
442
printf (" Error: Unable to read from file '%s'\n " , sInputFile .c_str ());
@@ -325,7 +445,13 @@ int32_t createSourceFile(
325
445
326
446
{
327
447
std::transform (sVarName .begin (), sVarName .end (), sVarName .begin (), ::toupper);
328
- iStatus = writeSourceFile (pBuffer, uiIntSize, sOutputFile , sVarName );
448
+
449
+ if (index == -1 )
450
+ {
451
+ iStatus = writeSourceFile (pBuffer, uiIntSize, sOutputFile , sVarName );
452
+ }else {
453
+ iStatus = writePartialSourceFile (pBuffer, uiIntSize, sOutputFile , sVarName , index, total);
454
+ }
329
455
}
330
456
331
457
finish:
@@ -445,10 +571,15 @@ void printUsage(const std::string &sProgram)
445
571
<< " (" << PARAM_I << " InPath)"
446
572
<< " [" << PARAM_O << " OutPath]"
447
573
<< " [" << PARAM_V << " VarName]"
574
+ << " [" << PARAM_INDEX << " Kernel Index]"
575
+ << " [" << PARAM_TOTAL << " Kernel Total]"
448
576
<< std::endl
449
577
<< " " << PARAM_I << " Path to Kernel binary input file (required)" << std::endl
450
578
<< " " << PARAM_O << " Path to Kernel binary output directory (optional)" << std::endl
451
- << " " << PARAM_V << " Variable Name on the generated source file (optional)" << std::endl;
579
+ << " " << PARAM_V << " Variable Name on the generated source file (optional)" << std::endl
580
+ << " " << PARAM_INDEX << " Variable kernel Index (optional)" << std::endl
581
+ << " " << PARAM_TOTAL << " Variable kernel total count (optional)" << std::endl;
582
+
452
583
}
453
584
454
585
// -----------------------------------------------------------------------------
@@ -460,7 +591,9 @@ int32_t parseInput(
460
591
const std::string &sProgram ,
461
592
std::string &sInput ,
462
593
std::string &sOutput ,
463
- std::string &sVarName )
594
+ std::string &sVarName ,
595
+ uint32_t &index,
596
+ uint32_t &total)
464
597
{
465
598
int32_t iStatus = -1 ;
466
599
@@ -484,6 +617,14 @@ int32_t parseInput(
484
617
{
485
618
sVarName = argv[i+1 ];
486
619
}
620
+ else if (0 == strcmp (PARAM_INDEX, argv[i]))
621
+ {
622
+ index = atoi (argv[i+1 ]);
623
+ }
624
+ else if (0 == strcmp (PARAM_TOTAL, argv[i]))
625
+ {
626
+ total = atoi (argv[i+1 ]) + 1 ;
627
+ }
487
628
else
488
629
{
489
630
std::cout << " Error: Invalid option " << argv[i] << std::endl;
@@ -527,21 +668,24 @@ int32_t main(int argc, char *argv[])
527
668
std::string sProgram = getFileName (argv[0 ]);
528
669
std::cout << std::endl
529
670
<< sProgram .c_str () << " v" << MAJ_VERSION << " ." << MIN_VERSION << std::endl
530
- << " (c) Intel Corporation 2017 . All rights reserved." << std::endl << std::endl;
671
+ << " (c) Intel Corporation 2019 . All rights reserved." << std::endl << std::endl;
531
672
532
673
int32_t iStatus = -1 ;
533
674
std::string sInputPath ;
534
675
std::string sOutputDir ;
535
676
std::string sVarName ;
677
+ uint32_t index=-1 ;
678
+ uint32_t total=-1 ;
536
679
537
- iStatus = parseInput (argc, argv, sProgram , sInputPath , sOutputDir , sVarName );
680
+ iStatus = parseInput (argc, argv, sProgram , sInputPath , sOutputDir , sVarName , index, total );
538
681
if (iStatus != 0 )
539
682
{
540
683
goto finish;
541
684
}
542
685
543
686
iStatus = createHeaderFile (sInputPath , sOutputDir , sVarName );
544
- iStatus = createSourceFile (sInputPath , sOutputDir , sVarName );
687
+
688
+ iStatus = createSourceFile (sInputPath , sOutputDir , sVarName , index, total);
545
689
546
690
finish:
547
691
return iStatus;
0 commit comments