Skip to content

Commit 193a064

Browse files
Gang Y Chenigcbot
Gang Y Chen
authored andcommitted
more clean up of shader-stats
old way of parsing asm file to collect opcode stats is not usable
1 parent 9462ea9 commit 193a064

File tree

3 files changed

+2
-231
lines changed

3 files changed

+2
-231
lines changed

IGC/common/Stats.cpp

-201
Original file line numberDiff line numberDiff line change
@@ -229,207 +229,6 @@ void ShaderStats::printShaderStats( ShaderHash hash, ShaderType shaderType, cons
229229
fclose(fileName);
230230
}
231231

232-
void ShaderStats::printOpcodeStats(ShaderHash hash, ShaderType shaderType, const std::string &postFix)
233-
{
234-
/*const std::string opcodeFilePath = IGC::Debug::GetShaderOutputFolder() + std::string("\\SQM\\") + IGC::Debug::GetShaderCorpusName() + "OpcodeShaderStats.csv";
235-
const char *opcodeFile = opcodeFilePath.c_str();
236-
237-
const std::string targetUnitFilePath = IGC::Debug::GetShaderOutputFolder() + std::string("\\SQM\\") + IGC::Debug::GetShaderCorpusName() + "TargetUnitShaderStats.csv";
238-
const char *targetUnitFile = targetUnitFilePath.c_str();
239-
240-
const std::string listFilePath = IGC::Debug::GetShaderOutputFolder() + std::string("\\SQM\\") + IGC::Debug::GetShaderCorpusName() + "ShadersList.txt";
241-
const char *listUnitFile = listFilePath.c_str();
242-
243-
FILE* opcodeFileName = fopen(opcodeFile, "a");
244-
FILE* targetUnitFileName = fopen(targetUnitFile, "a");
245-
FILE* listUnitFileName = fopen(listUnitFile, "a");
246-
247-
std::string asmFileName;
248-
if (shaderType == ShaderType::OPENCL_SHADER)
249-
{
250-
asmFileName =
251-
IGC::Debug::DumpName(IGC::Debug::GetShaderOutputName())
252-
.Type(shaderType)
253-
.Hash(hash)
254-
.PostFix(postFix)
255-
.Extension("asm")
256-
.str();
257-
if (asmFileName.find_last_of("\\") != std::string::npos)
258-
{
259-
asmFileName = asmFileName.substr(asmFileName.find_last_of("\\") + 1, asmFileName.size());
260-
}
261-
}
262-
else
263-
{
264-
asmFileName =
265-
IGC::Debug::DumpName(IGC::Debug::GetShaderOutputName())
266-
.Type(shaderType)
267-
.Hash(hash)
268-
.Extension("asm")
269-
.str();
270-
if (asmFileName.find_last_of("\\") != std::string::npos)
271-
{
272-
asmFileName = asmFileName.substr(asmFileName.find_last_of("\\") + 1, asmFileName.size());
273-
}
274-
}
275-
276-
277-
fprintf(opcodeFileName, "%s","");
278-
fclose(opcodeFileName);
279-
280-
fprintf(targetUnitFileName, "%s","");
281-
fclose(targetUnitFileName);
282-
283-
fprintf(listUnitFileName, "%s\n", asmFileName.c_str());
284-
fclose(listUnitFileName);
285-
?*/
286-
}
287-
288-
void ShaderStats::parseIsaShader( ShaderHash hash, ShaderType shaderType, SIMDMode simd )
289-
{
290-
291-
std::string line, instStr;
292-
293-
std::string asmFileName =
294-
IGC::Debug::DumpName(IGC::Debug::GetShaderOutputName())
295-
.Type(shaderType)
296-
.Hash(hash)
297-
.SIMDSize(simd)
298-
.Extension("asm")
299-
.str();
300-
if (asmFileName.find_last_of("\\") != std::string::npos)
301-
{
302-
asmFileName = asmFileName.substr(asmFileName.find_last_of("\\") + 1, asmFileName.size());
303-
}
304-
305-
std::ifstream asmFile(asmFileName.c_str());
306-
307-
while( getline(asmFile, line) )
308-
{
309-
if( line == ".code" )
310-
{
311-
break;
312-
}
313-
}
314-
315-
while( getline(asmFile, line) )
316-
{
317-
if( line == "" || line.find( "//", 0 ) == 0 || line == "main:" || line.find( "label", 0 ) == 0)
318-
{
319-
continue;
320-
}
321-
else if (line.find(" ", 0) == std::string::npos && line.find(":", 0) == line.size() - 1)
322-
{
323-
continue;
324-
}
325-
else if( line == ".end_code" )
326-
{
327-
break;
328-
}
329-
330-
if( line.find("(",0 ) == 0 )
331-
{
332-
line = line.substr( line.find(")",0) + 2, line.length() );
333-
}
334-
335-
instStr = line.substr( 0, line.find(" ", 0) );
336-
337-
auto hasDot = instStr.find(".",0);
338-
if (hasDot != std::string::npos)
339-
{
340-
instStr = instStr.substr( 0, hasDot );
341-
}
342-
343-
if( line.find("L",0) == 0 || line.find("_AUTO_LABEL", 0) == 0)
344-
{
345-
m_CompileShaderStats[STATS_ISA_BASIC_BLOCKS]++;
346-
}
347-
else if( instStr == "add" || instStr == "addc" || instStr == "avg" || instStr == "dp2" ||
348-
instStr == "dp3" || instStr == "dp4" || instStr == "dph" || instStr == "frc" ||
349-
instStr == "line" || instStr == "lrp" || instStr == "mac" || instStr == "mach" ||
350-
instStr == "mad" || instStr == "madm" || instStr == "math" || instStr == "mul" ||
351-
instStr == "pln" || instStr == "rndd" || instStr == "rnde" || instStr == "rndu" ||
352-
instStr == "rndz" || instStr == "sad2" || instStr == "sada2" || instStr == "subb" )
353-
{
354-
m_CompileShaderStats[STATS_ISA_ALU]++;
355-
}
356-
else if( instStr == "and" || instStr == "asr" || instStr == "bfe" || instStr == "bfi1" ||
357-
instStr == "bfi2" || instStr == "bfrev" || instStr == "cbit" || instStr == "fbh" ||
358-
instStr == "fbl" || instStr == "lzd" || instStr == "not" || instStr == "or" ||
359-
instStr == "shl" || instStr == "shr" || instStr == "xor" )
360-
{
361-
m_CompileShaderStats[STATS_ISA_LOGIC]++;
362-
}
363-
else if( instStr == "brc" || instStr == "brd" || instStr == "jumpi")
364-
{
365-
m_CompileShaderStats[STATS_ISA_THREADCF]++;
366-
}
367-
else if(instStr == "break" || instStr == "cont" || instStr == "while" ||
368-
instStr == "else" || instStr == "endif" || instStr == "if" )
369-
{
370-
m_CompileShaderStats[STATS_ISA_STRUCTCF]++;
371-
}
372-
else if( instStr == "goto" || instStr == "join" )
373-
{
374-
m_CompileShaderStats[STATS_ISA_GOTOJOIN]++;
375-
}
376-
else if( instStr == "call" || instStr == "calla" )
377-
{
378-
m_CompileShaderStats[STATS_ISA_CALL]++;
379-
}
380-
else if( instStr == "cmp" || instStr == "cmpn" || instStr == "csel" || instStr == "sel")
381-
{
382-
m_CompileShaderStats[STATS_ISA_SEL_CMP]++;
383-
}
384-
else if( instStr == "mov" || instStr == "movi" || instStr == "smov" )
385-
{
386-
m_CompileShaderStats[STATS_ISA_MOV]++;
387-
}
388-
else if( instStr == "send" || instStr == "sendc" || instStr == "sends" )
389-
{
390-
m_CompileShaderStats[STATS_ISA_SEND]++;
391-
}
392-
else if( instStr == "halt" || instStr == "illegal" || instStr == "nop" || instStr == "wait" ||
393-
instStr == "ret" )
394-
{
395-
m_CompileShaderStats[STATS_ISA_OTHERS]++;
396-
}
397-
else if( line.find( "_GOTO_TARGET", 0 ) == 0 )
398-
{
399-
;
400-
}
401-
else
402-
{
403-
IGC_ASSERT(0);
404-
}
405-
}
406-
407-
int statsIndex = STATS_ISA_INST_COUNT;
408-
if( simd == SIMDMode::SIMD16 )
409-
{
410-
statsIndex = STATS_ISA_INST_COUNT_SIMD16;
411-
}
412-
else if( simd == SIMDMode::SIMD32 )
413-
{
414-
statsIndex = STATS_ISA_INST_COUNT_SIMD32;
415-
}
416-
417-
for( int i=STATS_ISA_ALU; i<STATS_MAX_SHADER_STATS_ITEMS; i++)
418-
{
419-
m_CompileShaderStats[statsIndex] += m_CompileShaderStats[i];
420-
}
421-
422-
if( simd == SIMDMode::SIMD16 )
423-
{
424-
m_CompileShaderStats[STATS_ISA_INST_COUNT_SIMD16] -= m_CompileShaderStats[STATS_ISA_INST_COUNT];
425-
}
426-
else if( simd == SIMDMode::SIMD32 )
427-
{
428-
m_CompileShaderStats[STATS_ISA_INST_COUNT_SIMD32] -= m_CompileShaderStats[STATS_ISA_INST_COUNT];
429-
}
430-
asmFile.close();
431-
}
432-
433232
void ShaderStats::sumShaderStat( SHADER_STATS_ITEMS compileInterval, int count )
434233
{
435234
IGC_ASSERT(0 <= compileInterval);

IGC/common/Stats.hpp

+2-19
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ SPDX-License-Identifier: MIT
1515
#if defined( _INTERNAL ) || defined( _DEBUG )
1616
#define GET_SHADER_STATS 1
1717
#define PRINT_PER_SHADER_STATS 1
18-
#define PRINT_DETAIL_SHADER_STATS 0
1918
#define GET_MEM_STATS 1
2019
#endif
2120

@@ -68,8 +67,6 @@ class ShaderStats
6867
}
6968

7069
void printShaderStats(ShaderHash hash, ShaderType shaderType, const std::string &postFix);
71-
void printOpcodeStats(ShaderHash hash, ShaderType shaderType, const std::string &postFix);
72-
void parseIsaShader(ShaderHash hash, ShaderType shaderType, SIMDMode simd);
7370
int getShaderStats(SHADER_STATS_ITEMS compileInterval);
7471
void sumShaderStat(SHADER_STATS_ITEMS compileInterval, int count);
7572
void miscSumShaderStat(ShaderStats* sStats);
@@ -84,28 +81,14 @@ class ShaderStats
8481
int m_TotalSimd32;
8582
};
8683

87-
#if PRINT_DETAIL_SHADER_STATS
88-
#define COMPILER_SHADER_STATS_PRINT( shaderStats, shaderType, hash, postFix ) \
89-
do \
90-
{ \
91-
if( shaderStats ) \
92-
{ \
93-
(shaderStats)->parseIsaShader( hash, shaderType, SIMDMode::SIMD8 ); \
94-
if( shaderType == ShaderType::PIXEL_SHADER || shaderType == ShaderType::COMPUTE_SHADER ) \
95-
{ \
96-
(shaderStats)->parseIsaShader( hash, shaderType, SIMDMode::SIMD16 ); \
97-
(shaderStats)->parseIsaShader( hash, shaderType, SIMDMode::SIMD32 ); \
98-
} \
99-
} \
100-
} while (0)
101-
#elif PRINT_PER_SHADER_STATS
84+
85+
#if PRINT_PER_SHADER_STATS
10286
#define COMPILER_SHADER_STATS_PRINT( shaderStats, shaderType, hash, postFix) \
10387
do \
10488
{ \
10589
if( shaderStats ) \
10690
{ \
10791
(shaderStats)->printShaderStats( hash, shaderType, postFix ); \
108-
(shaderStats)->printOpcodeStats( hash, shaderType, postFix ); \
10992
} \
11093
} while (0)
11194
#else

IGC/common/shaderStats.h

-11
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,4 @@ DEFINE_SHADER_STAT( STATS_ISA_CYCLE_ESTIMATE32, "simd32 cycle estimate
2323
DEFINE_SHADER_STAT( STATS_ISA_STALL_ESTIMATE8, "simd8 stall estimate")
2424
DEFINE_SHADER_STAT( STATS_ISA_STALL_ESTIMATE16, "simd16 stall estimate")
2525
DEFINE_SHADER_STAT( STATS_ISA_STALL_ESTIMATE32, "simd32 stall estimate")
26-
DEFINE_SHADER_STAT( STATS_ISA_BASIC_BLOCKS, "Basic Blocks" )
27-
DEFINE_SHADER_STAT( STATS_ISA_ALU, "Alu" )
28-
DEFINE_SHADER_STAT( STATS_ISA_LOGIC, "Logic" )
29-
DEFINE_SHADER_STAT( STATS_ISA_MOV, "Mov" )
30-
DEFINE_SHADER_STAT( STATS_ISA_SEND, "Send" )
31-
DEFINE_SHADER_STAT( STATS_ISA_SEL_CMP, "Select/Compare" )
32-
DEFINE_SHADER_STAT( STATS_ISA_STRUCTCF, "Struct CF" )
33-
DEFINE_SHADER_STAT( STATS_ISA_GOTOJOIN, "Goto Join" )
34-
DEFINE_SHADER_STAT( STATS_ISA_THREADCF, "Thread CF" )
35-
DEFINE_SHADER_STAT( STATS_ISA_CALL, "Call" )
36-
DEFINE_SHADER_STAT( STATS_ISA_OTHERS, "Others" )
3726
DEFINE_SHADER_STAT( STATS_MAX_SHADER_STATS_ITEMS, "" )

0 commit comments

Comments
 (0)