source: CLRX/CLRadeonExtender/trunk/CLRX/amdbin/ROCmBinaries.h @ 2522

Last change on this file since 2522 was 2522, checked in by matszpk, 4 years ago

CLRadeonExtender: Disasm: add dump of kernel config for ROCm binaries.

File size: 4.1 KB
Line 
1/*
2 *  CLRadeonExtender - Unofficial OpenCL Radeon Extensions Library
3 *  Copyright (C) 2014-2016 Mateusz Szpakowski
4 *
5 *  This library is free software; you can redistribute it and/or
6 *  modify it under the terms of the GNU Lesser General Public
7 *  License as published by the Free Software Foundation; either
8 *  version 2.1 of the License, or (at your option) any later version.
9 *
10 *  This library is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 *  Lesser General Public License for more details.
14 *
15 *  You should have received a copy of the GNU Lesser General Public
16 *  License along with this library; if not, write to the Free Software
17 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19/*! \file ROCmBinaries.h
20 * \brief ROCm binaries handling
21 */
22
23#ifndef __CLRX_ROCMBINARIES_H__
24#define __CLRX_ROCMBINARIES_H__
25
26#include <CLRX/Config.h>
27#include <cstddef>
28#include <cstdint>
29#include <memory>
30#include <string>
31#include <CLRX/amdbin/Elf.h>
32#include <CLRX/amdbin/ElfBinaries.h>
33#include <CLRX/utils/MemAccess.h>
34#include <CLRX/utils/Containers.h>
35#include <CLRX/utils/Utilities.h>
36
37/// main namespace
38namespace CLRX
39{
40
41enum : Flags {
42    ROCMBIN_CREATE_REGIONMAP = 0x10,    ///< create region map
43   
44    ROCMBIN_CREATE_ALL = ELF_CREATE_ALL | 0xfff0 ///< all ROCm binaries flags
45};
46
47/// ROCm data region
48struct ROCmRegion
49{
50    CString regionName; ///< region name
51    size_t size;    ///< data size
52    uint64_t offset;     ///< data
53    bool isKernel;
54};
55
56/// ROCm main binary for GPU for 64-bit mode
57/** This object doesn't copy binary code content.
58 * Only it takes and uses a binary code.
59 */
60class ROCmBinary : public ElfBinary64, public NonCopyableAndNonMovable
61{
62public:
63    typedef Array<std::pair<CString, size_t> > RegionMap;
64private:
65    size_t regionsNum;
66    std::unique_ptr<ROCmRegion[]> regions;  ///< AMD metadatas
67    RegionMap regionsMap;
68    size_t codeSize;
69    cxbyte* code;
70public:
71    ROCmBinary(size_t binaryCodeSize, cxbyte* binaryCode,
72            Flags creationFlags = ROCMBIN_CREATE_ALL);
73    ~ROCmBinary() = default;
74   
75    /// get regions number
76    size_t getRegionsNum() const
77    { return regionsNum; }
78   
79    /// get region by index
80    const ROCmRegion& getRegion(size_t index) const
81    { return regions[index]; }
82   
83    /// get region by name
84    const ROCmRegion& getRegion(const char* name) const;
85   
86    /// get code size
87    size_t getCodeSize() const
88    { return codeSize; }
89    /// get code
90    const cxbyte* getCode() const
91    { return code; }
92   
93    /// returns true if kernel map exists
94    bool hasRegionMap() const
95    { return (creationFlags & ROCMBIN_CREATE_REGIONMAP) != 0; };
96};
97
98/// ROCm kernel configuration structure
99struct ROCmKernelConfig
100{
101    uint32_t amdCodeVersionMajor;
102    uint32_t amdCodeVersionMinor;
103    uint16_t amdMachineKind;
104    uint16_t amdMachineMajor;
105    uint16_t amdMachineMinor;
106    uint16_t amdMachineStepping;
107    uint64_t kernelCodeEntryOffset;
108    uint64_t kernelCodePrefetchOffset;
109    uint64_t kernelCodePrefetchSize;
110    uint64_t maxScrachBackingMemorySize;
111    uint32_t computePgmRsrc1;
112    uint32_t computePgmRsrc2;
113    uint16_t enableSpgrRegisterFlags;
114    uint16_t enableFeatureFlags;
115    uint32_t workitemPrivateSegmentSize;
116    uint32_t workgroupGroupSegmentSize;
117    uint32_t gdsSegmentSize;
118    uint64_t kernargSegmentSize;
119    uint32_t workgroupFbarrierCount;
120    uint16_t wavefrontSgprCount;
121    uint16_t workitemVgprCount;
122    uint16_t reservedVgprFirst;
123    uint16_t reservedVgprCount;
124    uint16_t reservedSgprFirst;
125    uint16_t reservedSgprCount;
126    uint16_t debugWavefrontPrivateSegmentOffsetSgpr;
127    uint16_t debugPrivateSegmentBufferSgpr;
128    cxbyte kernargSegmentAlignment;
129    cxbyte groupSegmentAlignment;
130    cxbyte privateSegmentAlignment;
131    cxbyte wavefrontSize;
132    uint32_t callConvention;
133    uint32_t reserved1[3];
134    uint64_t runtimeLoaderKernelSymbol;
135    cxbyte controlDirective[128];
136};
137
138/// check whether is Amd OpenCL 2.0 binary
139extern bool isROCmBinary(size_t binarySize, const cxbyte* binary);
140
141};
142
143#endif
Note: See TracBrowser for help on using the repository browser.