Skip to content

Commit 3ed6bd6

Browse files
DianaChensys_zuul
authored andcommitted
Write IGC program output to ZE binary, disable by default
Change-Id: I6a9b6a906a58147787ca77374865368c293e10ad
1 parent 0429096 commit 3ed6bd6

File tree

14 files changed

+823
-48
lines changed

14 files changed

+823
-48
lines changed

IGC/AdaptorOCL/CLElfLib/CLElfTypes.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ Abstract: Defines the types used for ELF headers/sections. This uses
3838
#include <inttypes.h>
3939
#endif
4040

41-
#if defined(__linux__)
42-
#include "elf.h"
43-
#endif
44-
4541
#include <stddef.h>
4642

4743
namespace CLElfLib

IGC/AdaptorOCL/OCL/KernelAnnotations.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,13 @@ struct ExecutionEnivronment
298298
//legacy design:not used
299299
//new design: hold private memory used by shader if non-ZERO
300300
DWORD PerThreadScratchSpaceSlot1 = 0;
301+
// Size in bytes of the stateless memory requirement for allocating
302+
// private variables.
303+
// This field is added for zebin
304+
// The same information for path token based format is passed in
305+
// PrivateMemSizeAnnotation which will point to a PrivateInputAnnotation
306+
// that contains the size
307+
DWORD PerThreadPrivateOnStatelessSize = 0;
301308
//legacy design:not used
302309
//new design: hold private memory used by shader if non-ZERO
303310
DWORD SumFixedTGSMSizes = 0;

IGC/AdaptorOCL/OCL/sp/sp_g8.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class DisallowCopy
7979
DisallowCopy& operator=(const DisallowCopy&);
8080
};
8181

82+
/// CGen8OpenCLStateProcessor - Provides services to create (legacy) patch token
83+
/// based binary from given SProgramOutput information
8284
class CGen8OpenCLStateProcessor : DisallowCopy
8385
{
8486

IGC/AdaptorOCL/OCL/sp/spp_g8.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,67 @@ void overrideOCLKernelBinary(
226226
KernBin->Write(Buf.get(), newBinarySize);
227227
}
228228

229+
230+
void CGen8OpenCLProgram::GetZEBinary(
231+
llvm::raw_pwrite_stream& programBinary, unsigned pointerSizeInBytes)
232+
{
233+
auto isValidShader = [&](IGC::COpenCLKernel* shader)->bool
234+
{
235+
return (shader && shader->ProgramOutput()->m_programSize > 0);
236+
};
237+
238+
ZEBinaryBuilder zebuilder(m_Platform, pointerSizeInBytes, m_pContext->m_programInfo);
239+
240+
for (auto pKernel : m_ShaderProgramList)
241+
{
242+
IGC::COpenCLKernel* simd8Shader = static_cast<IGC::COpenCLKernel*>(pKernel->GetShader(SIMDMode::SIMD8));
243+
IGC::COpenCLKernel* simd16Shader = static_cast<IGC::COpenCLKernel*>(pKernel->GetShader(SIMDMode::SIMD16));
244+
IGC::COpenCLKernel* simd32Shader = static_cast<IGC::COpenCLKernel*>(pKernel->GetShader(SIMDMode::SIMD32));
245+
246+
// Determine how many simd modes we have per kernel
247+
// FIXME: We actually expect only one simd mode per kernel. There should not be multiple SIMD mode available
248+
// for one kernel (runtime cannot support that). So these check can be simplified
249+
std::vector<IGC::COpenCLKernel*> kernelVec;
250+
if (m_pContext->m_DriverInfo.sendMultipleSIMDModes() && (m_pContext->getModuleMetaData()->csInfo.forcedSIMDSize == 0))
251+
{
252+
// For multiple SIMD modes, send SIMD modes in descending order
253+
if (isValidShader(simd32Shader))
254+
kernelVec.push_back(simd32Shader);
255+
if (isValidShader(simd16Shader))
256+
kernelVec.push_back(simd16Shader);
257+
if (isValidShader(simd8Shader))
258+
kernelVec.push_back(simd8Shader);
259+
}
260+
else
261+
{
262+
if (isValidShader(simd32Shader))
263+
kernelVec.push_back(simd32Shader);
264+
else if (isValidShader(simd16Shader))
265+
kernelVec.push_back(simd16Shader);
266+
else if (isValidShader(simd8Shader))
267+
kernelVec.push_back(simd8Shader);
268+
}
269+
270+
for (auto kernel : kernelVec)
271+
{
272+
IGC::SProgramOutput* pOutput = kernel->ProgramOutput();
273+
274+
zebuilder.createKernel(
275+
(const char*)pOutput->m_programBin,
276+
pOutput->m_programSize,
277+
kernel->m_kernelInfo,
278+
kernel->getGRFSize());
279+
280+
// FIXME: Handle IGC_IS_FLAG_ENABLED(ShaderDumpEnable) and
281+
// IGC_IS_FLAG_ENABLED(ShaderOverride)
282+
283+
// ... Create the debug data binary streams
284+
}
285+
}
286+
287+
zebuilder.getBinaryObject(programBinary);
288+
}
289+
229290
void CGen8OpenCLProgram::CreateKernelBinaries()
230291
{
231292
auto isValidShader = [&](IGC::COpenCLKernel* shader)->bool

IGC/AdaptorOCL/OCL/sp/spp_g8.h

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3333
#include "../util/BinaryStream.h"
3434
#include "usc.h"
3535
#include "sp_g8.h"
36+
#include "zebin_builder.hpp"
3637

3738
namespace IGC
3839
{
@@ -64,23 +65,35 @@ class CGen8OpenCLProgramBase : DisallowCopy {
6465
explicit CGen8OpenCLProgramBase(PLATFORM platform);
6566
virtual ~CGen8OpenCLProgramBase();
6667

68+
/// GetProgramBinary - getting legacy (Patch token based) binary format
69+
/// Write program header and the already written patch token info
70+
/// and kernels' binary to programBinary. Must be called after
71+
/// CGen8OpenCLProgram::CreateKernelBinaries or CGen8CMProgram::CreateKernelBinaries
6772
RETVAL GetProgramBinary(Util::BinaryStream& programBinary,
6873
unsigned pointerSizeInBytes);
69-
74+
/// GetProgramDebugData - get debug data binary for legacy (Patch token based)
75+
/// binary format
7076
RETVAL GetProgramDebugData(Util::BinaryStream& programDebugData);
71-
77+
/// CreateProgramScopePatchStream - get program scope patch token for legacy
78+
/// (Patch token based) binary format
7279
void CreateProgramScopePatchStream(const IGC::SOpenCLProgramInfo& programInfo);
7380

74-
// Used to store per-kernel binary streams and kernelInfo
81+
// For per-kernel binary streams and kernelInfo
7582
std::vector<KernelData> m_KernelBinaries;
7683

7784
USC::SSystemThreadKernelOutput* m_pSystemThreadKernelOutput = nullptr;
7885

7986
PLATFORM getPlatform() const { return m_Platform; }
8087

88+
public:
89+
// GetZEBinary - get ZE binary object
90+
virtual void GetZEBinary(Util::BinaryStream& programBinary,
91+
unsigned pointerSizeInBytes) {}
92+
8193
protected:
8294
PLATFORM m_Platform;
8395
CGen8OpenCLStateProcessor m_StateProcessor;
96+
// For serialized patch token information
8497
Util::BinaryStream* m_ProgramScopePatchStream = nullptr;
8598
};
8699

@@ -91,8 +104,14 @@ class CGen8OpenCLProgram : public CGen8OpenCLProgramBase
91104

92105
~CGen8OpenCLProgram();
93106

107+
/// API for getting legacy (Patch token based) binary
108+
/// CreateKernelBinaries - write patch token information and gen binary to
109+
/// m_ProgramScopePatchStream and m_KernelBinaries
94110
void CreateKernelBinaries();
95111

112+
/// getZEBinary - create ZE Binary
113+
void GetZEBinary(llvm::raw_pwrite_stream& programBinary, unsigned pointerSizeInBytes);
114+
96115
// Used to track the kernel info from CodeGen
97116
std::vector<IGC::CShaderProgram*> m_ShaderProgramList;
98117

0 commit comments

Comments
 (0)