source: CLRX/CLRadeonExtender/trunk/amdbin/ROCmBinaries.cpp @ 2501

Last change on this file since 2501 was 2501, checked in by matszpk, 3 years ago

CLRadeonExtender: Add function to checking whether binary is ROCm binary.

File size: 2.0 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
20#include <CLRX/Config.h>
21#include <cstdlib>
22#include <cstring>
23#include <climits>
24#include <cstdint>
25#include <map>
26#include <utility>
27#include <vector>
28#include <CLRX/amdbin/Elf.h>
29#include <CLRX/utils/Utilities.h>
30#include <CLRX/utils/MemAccess.h>
31#include <CLRX/amdbin/ROCmBinaries.h>
32
33using namespace CLRX;
34
35ROCmBinary::ROCmBinary(size_t binaryCodeSize, cxbyte* binaryCode, Flags creationFlags)
36        : ElfBinary64(binaryCodeSize, binaryCode, creationFlags)
37{
38}
39
40const ROCmKernel& ROCmBinary::getKernel(const char* name) const
41{
42    KernelMap::const_iterator it = binaryMapFind(kernelsMap.begin(),
43                             kernelsMap.end(), name);
44    if (it == kernelsMap.end())
45        throw Exception("Can't find kernel name");
46    return kernels[it->second];
47}
48
49bool CLRX::isROCmBinary(size_t binarySize, const cxbyte* binary)
50{
51    if (!isElfBinary(binarySize, binary))
52        return false;
53    if (binary[EI_CLASS] != ELFCLASS64)
54        return false;
55    const Elf64_Ehdr* ehdr = reinterpret_cast<const Elf64_Ehdr*>(binary);
56    if (ULEV(ehdr->e_machine) != 0xe0 || ULEV(ehdr->e_flags)!=0)
57        return false;
58    return true;
59}
Note: See TracBrowser for help on using the repository browser.