1 /*========================== begin_copyright_notice ============================
2 
3 Copyright (C) 2017-2021 Intel Corporation
4 
5 SPDX-License-Identifier: MIT
6 
7 ============================= end_copyright_notice ===========================*/
8 
9 #pragma once
10 #include "Compiler/CISACodeGen/ComputeShaderBase.hpp"
11 
12 namespace IGC
13 {
14     class KernelArg;
15 }
16 
17 namespace IGC
18 {
19 
20     class COpenCLKernel : public CComputeShaderBase
21     {
22     public:
23         friend class CShaderProgram;
24         COpenCLKernel(const OpenCLProgramContext* ctx, llvm::Function*, CShaderProgram* pProgram);
25         ~COpenCLKernel();
26 
27         void PreCompile() override;
28         void AllocatePayload() override;
29         void ParseShaderSpecificOpcode(llvm::Instruction* inst) override;
ExtractGlobalVariables()30         void ExtractGlobalVariables() override {}
31 
32         bool        hasReadWriteImage(llvm::Function& F) override;
33         bool        CompileSIMDSize(SIMDMode simdMode, EmitPass& EP, llvm::Function& F) override;
34         SIMDStatus  checkSIMDCompileConds(SIMDMode simdMode, EmitPass& EP, llvm::Function& F);
35 
36         void        FillKernel();
37 
38         // Recomputes the binding table layout according to the present kernel args
39         void RecomputeBTLayout();
40 
41         // Set m_HasTID to true if TID functions were found
42         void SetHasTID();
43 
44         // Set m_HasGlobalSize to true if TID functions were found
45         void SetHasGlobalSize();
46 
47         bool HasFullDispatchMask() override;
48 
49         // Returns the immediate value mapped to GlobalVariable c.
50         // (GlobalVariables represent the pointer to the global,
51         // which is a compile-time constant)
52         unsigned int GetGlobalMappingValue(llvm::Value* c) override;
53         CVariable* GetGlobalMapping(llvm::Value* c) override;
54 
getKernelInfo() const55         const SOpenCLKernelInfo& getKernelInfo() const { return m_kernelInfo; }
56 
57     public:
58         SOpenCLProgramInfo* m_programInfo;
59         SOpenCLKernelInfo m_kernelInfo;
60 
61         unsigned int m_perWIStatelessPrivateMemSize;
62 
GetDisableMidThreadPreemption() const63         bool        GetDisableMidThreadPreemption() const { return m_disableMidThreadPreemption; }
SetDisableMidthreadPreemption()64         void        SetDisableMidthreadPreemption() { m_disableMidThreadPreemption = true; }
65 
66     protected:
67         // Creates appropriate annotation based on the kernel arg
68         void CreateAnnotations(IGC::KernelArg* kernelArg, uint payloadPosition);
69 
70         // Fill SOpenCLKernelInfo::m_zePayloadArgs
71         // Return true: if the argument is supported in ZEBinary and it's created successfully
72         // Return false: if the argument cannot be supported by ZEBinary
73         bool CreateZEPayloadArguments(IGC::KernelArg* kernelArg, uint payloadPosition);
74 
75         // a helper function to get image type from kernelArg
76         iOpenCL::IMAGE_MEMORY_OBJECT_TYPE getImageTypeFromKernelArg(const KernelArg& kernelArg);
77 
78         // Creates annotations for inline sampler_t objects
79         void CreateInlineSamplerAnnotations();
80 
81         // Creates annotations for kernel argument information (kernel reflection)
82         void CreateKernelArgInfo();
83 
84         // Creates annotations for kernel attribution information (kernel reflection)
85         void CreateKernelAttributeInfo();
86         std::string getVecTypeHintString(IGC::IGCMD::VectorTypeHintMetaDataHandle& vecTypeHintInfo);
87         std::string getThreadGroupSizeString(IGC::IGCMD::ThreadGroupSizeMetaDataHandle& threadGroupSize, bool isHint);
88         std::string getSubGroupSizeString(IGC::IGCMD::SubGroupSizeMetaDataHandle& subGroupSize);
89         std::string getWorkgroupWalkOrderString(const IGC::WorkGroupWalkOrderMD& workgroupWalkOrder);
90         // Create annotation for printf strings.
91         void CreatePrintfStringAnnotations();
92 
93         // Load from MD and return the resource information for argument number argNo
94         SOpenCLKernelInfo::SResourceInfo getResourceInfo(int argNo);
95 
96         // Load from MD and return the resource extension information for argument number argNo
97         ResourceExtensionTypeEnum getExtensionInfo(int argNo);
98 
99         // Resolve the binding table index for resource resInfo (using the BTL)
100         unsigned int getBTI(SOpenCLKernelInfo::SResourceInfo& resInfo);
101 
102         // Find the sum of inline local sizes used by this kernel
103         unsigned int getSumFixedTGSMSizes(llvm::Function* F);
104 
105         bool m_HasTID;
106         bool m_HasGlobalSize;
107         bool m_disableMidThreadPreemption;
108 
109         // Maps GlobalVariables representing local address-space pointers
110         // to their offsets in SLM.
111         std::map<llvm::Value*, unsigned int> m_localOffsetsMap;
112 
113         OpenCLProgramContext* m_Context;
114 
115         void ClearKernelInfo();
116     private:
117         bool hasWorkGroupWalkOrder();
118     };
119 
120 }
121