Giter Club home page Giter Club logo

hsail-tools's Introduction

HSAIL-Tools

build status

OVERVIEW

HSAIL-Tools are used for parsing, assembling, and disassembling HSAIL.

The following components are provided:

  • libHSAIL is the main library.
  • libHSAIL-AMD is the library with AMD HSAIL extensions.
  • HSAILAsm is command-line interface to libHSAIL.

This version of libHSAIL supports HSA PRM 1.02 (Final) specification.

BUILD PREREQUISITES

libHSAIL requires the following components:

  • CMake
  • libelf (if BUILD_WITH_LIBBRIGDWARF=1)
  • libdwarf (if BUILD_WITH_LIBBRIGDWARF=1)
  • perl
  • re2c

libHSAIL CMake build will automatically find these dependencies if installed.

libHSAIL can be built without debug support and does not require libelf/libdwarf in this case.

BUILD (general)

We recommend to use out-of-source CMake build and create separate directory to run CMake.

To build libHSAIL without BRIG DWARF (no debug support), specify -DBUILD_WITH_LIBBRIGDWARF=OFF option to CMake.

To avoid building HSAILAsm, specify -DBUILD_HSAILASM=OFF option to CMake.

To avoid building all vendor extensions, specify -DVENDOR_EXTENSIONS=OFF option to CMake.

To avoid building AMD extensions, specify -DAMD_EXTENSIONS=OFF option to CMake.

A set of tests is included and can be run with 'make test' (requires HSAILAsm to be built).

To enable additional syntax validation tests, specify -DSYNTAX_VALIDATION_TESTS=ON option to CMake.

BUILD (Linux)

mkdir -p build/lnx64
cd build/lnx64
cmake ../..
make -j

On modern Linux distributions libHSAIL dependencies are typically provided by the distribution. For example, the following command can be used to install them on Ubuntu 14.04 system:

sudo apt-get install cmake libdwarf-dev libelf-dev llvm-dev ncurses-dev re2c perl

Building on Linux requires GCC 4.8+.

On Linux, CMake normally finds all dependencies automatically. However, it is also possible to override it (see, for example, scripts in bin/ subdirectory).

BUILD (Windows)

Building on Windows requires MSVC (Visual Studio 2012 Update 4 or later).

CMake command line should specify compiler configuration:

md build/win64
cd build/win64
cmake -G "Visual Studio 12 2013 Win64" ...

CMake will attempt to locate corresponding compiler and generate Visual Studio solution file which can be opened and built in Visual Studio.

For Windows, it is possible to obtain dependencies from corresponding software sources:

On Windows, cmake command line additionally might need to include the location of dependencies. Refer to scripts in bin/ subdirectory for an example how to specify them.

hsail-tools's People

Contributors

arsenm avatar atamazov avatar bensander avatar bmwiedemann avatar dfukalov avatar dpreobra avatar emankov avatar huybui1 avatar jvesely avatar kasaurov avatar nhaustov avatar osemenov avatar samwot avatar scchan avatar tjablin avatar vpykhtin avatar whchung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hsail-tools's Issues

Query: Why error messages are not terminated with newlines?

Hi HSAIL Tools Team,
Could you please inform me why error messages are not terminated with newlines in HSAILBrigObjectFile.cpp (It looks a bit odd)?
I see that in most cases where the error stream is written, 1 is returned (to indicate error), but there are cases when it is possible that the error stream is written, but 0 could be returned.

In some other places (eg. HSAILValidator.cpp), error messages end with new line.

Thanks in advance for your help.

libHSA builds with rtti by default

Currently, libHSA builds with rtti, but LLVM on Linux builds with -fno-rtti by default. For better compatibility with existing builds of LLVM, I recommend modifying the Makefile as follows:

-CXXFLAGS += -c -o $@
+CXXFLAGS += -fno-rtti -c -o $@

Nop Instruction is not parsed correctly

The nop instruction is not parsed correctly. Here is a simple test case:

version 0:96:$full:$large;

kernel &foo() {
nop;
ret;
};

The underlying problem is that addNop in HSAILBrigantine.cpp thinks that the BrigKind of a nop instruction is BrigNone, but the HSA PRM 19.10.7 indicates it should be BRIG_INST_BASIC.

HSAILasm disassembles an illegal BRIG with an illegal store argument list without complaining

There's an illegal instruction in a BRIG:

st_align(4)_u8 9, 0, 0, 0, [$d0+8];

st takes only two arguments, this has somehow pushed in 5. HSAILasm can disassemble the BRIG, but cannot assemble it again:

$ HSAILasm -disassemble phsa-temp/program-0.brig
$ HSAILasm phsa-temp/program-0.hsail

  st_align(4)_u8  9, 0, 0, 0, [$d0+8];
                     ^

input(10,20): Invalid operand 1, expected: an address

See: HSAFoundation/gccbrig#4

Compiler error building libHSAIL

/home/bsp/HSAIL-Tools/libHSAIL/libHSAIL/BrigDwarfGenerator.cpp: In member function âvoid BrigDebug::BrigDwarfGenerator_impl::initializeDwarfProducer()â:
/home/bsp/HSAIL-Tools/libHSAIL/libHSAIL/BrigDwarfGenerator.cpp:515:50: error: invalid conversion from âint ()(const char, int, Dwarf_Unsigned, Dwarf_Unsigned, Dwarf_Unsigned, Dwarf_Unsigned, Dwarf_Unsigned_, void_, int_) {aka int ()(const char, int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int_, void_, int_)}â to âDwarf_Callback_Func {aka int ()(char, int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, int_, int_)}â [-fpermissive]
&pErr );
^
/home/bsp/HSAIL-Tools/libHSAIL/libHSAIL/BrigDwarfGenerator.cpp:515:50: error: cannot convert âBrigDebug::BrigDwarfGenerator_impl* constâ to âDwarf_Error_sâ for argument â5â to âDwarf_P_Debug_s* dwarf_producer_init(Dwarf_Unsigned, Dwarf_Callback_Func, Dwarf_Handler, Dwarf_Ptr, Dwarf_Error_s
/home/bsp/HSAIL-Tools/libHSAIL/libHSAIL/BrigDwarfGenerator.cpp: In member function âDwarf_P_Die_s* BrigDebug::BrigDwarfGenerator_impl::generateDwarfForBrigSymbol(HSAIL_ASM::Directive, Dwarf_P_Die, unsigned int)â:
/home/bsp/HSAIL-Tools/libHSAIL/libHSAIL/BrigDwarfGenerator.cpp:604:29: warning: unused variable âpBdsâ [-Wunused-variable]
BrigDirectiveVariable * pBds( dSym.brig() );
^
make[2]: *** [libHSAIL/CMakeFiles/hsail.dir/BrigDwarfGenerator.cpp.o] Error 1
make[1]: *** [libHSAIL/CMakeFiles/hsail.dir/all] Error 2
make: *** [all] Error 2

Divergence between libHSAIL and HSA spec: BrigDirectiveVersion

We're working with the 0.95 version of the HSA PRM (there doesn't seem to
be any newer one). That spec says that BrigDirectiveVersion has this format:

struct BrigDirectiveVersion {
   uint16_t size;
   BrigDirectiveKinds16_t kind;
   BrigCodeOffset32_t code;
   uint16_t major;
   uint16_t minor;
   BrigProfile8_t profile;
   BrigMachineModel8_t machineModel;
   uint16_t reserved;
};

libHSAIL (Brig_new.hpp) defines it as:

struct BrigDirectiveVersion { //.parent=BrigDirectiveCode
    uint16_t               size;
    BrigDirectiveKinds16_t kind;
    BrigCodeOffset32_t     code;
    BrigVersion32_t        hsailMajor;  //.novisit // TBD095 make visitor
    BrigVersion32_t        hsailMinor;  //.novisit // TBD095 make visitor
    BrigVersion32_t        brigMajor;   //.novisit // TBD095 make visitor
    BrigVersion32_t        brigMinor;   //.novisit // TBD095 make visitor
    BrigProfile8_t         profile;
    BrigMachineModel8_t    machineModel;
    uint16_t reserved;                  //.defValue=0
};

It also contains a commented out variant that matches the spec, but
the above is the one that's used. This caused verification errors when
we emitted BRIG from GCC as per the spec. So please either change
the spec or libHSAIL.

Test HSAIL code file is not updated

The HSAIL file in the tests directory is still written in the 0.96 format. It cannot be assembled by the assembler committed in Sep 2014.

libBRIGdwarf does not compile using recent versions of libdwarf

In versions of libdwarf more recent than 20140413, the procedure
dwarf_producer_init_c
has been removed.

Consequently, the compilation fails in libBRIGdwarf/BrigDwarfGenerator.cpp in member function ‘void BrigDebug::BrigDwarfGenerator_impl::initializeDwarfProducer()’

The Assembler does not Scan Octal Literals Correctly

$ echo "version 1:0:$large; global_u8 &n = 0256;" > test.hsail
$ hsailasm test.hsail

version 1:0:$large; global_u8 &n = 0256;
^
input(1,36): value doesn't fit into destination

In HSAILScannerRules.re2c, shouldn't: DECIMAL = DCD+;
be: DECIMAL = [1-9]DCD*;

HSAILasm linking failure with older llvm

/usr/bin/c++ -Wall -std=c++11 -pthread -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -fno-rtti -fvisibility-inlines-hidden CMakeFiles/HSAILasm.dir/HSAILAsm.cpp.o -o HSAILasm -rdynamic ../libHSAIL/libhsail.a -lelf -ldwarf -lcurses -ldl -ltinfo /usr/lib64/libdwarf.so
../libHSAIL/libhsail.a(BrigDwarfGenerator.cpp.o): In function BrigDebug::BrigDwarfGenerator_impl::initializeElf()': BrigDwarfGenerator.cpp:(.text+0x26ae): warning: the use oftempnam' is dangerous, better use mkstemp' CMakeFiles/HSAILasm.dir/HSAILAsm.cpp.o: In functionmain':
HSAILAsm.cpp:(.text+0x1a): undefined reference to llvm::sys::PrintStackTraceOnErrorSignal()' CMakeFiles/HSAILasm.dir/HSAILAsm.cpp.o: In functionllvm::PrettyStackTraceProgram::PrettyStackTraceProgram(int, char const* const*)':
HSAILAsm.cpp:(.text._ZN4llvm23PrettyStackTraceProgramC2EiPKPKc[_ZN4llvm23PrettyStackTraceProgramC5EiPKPKc]+0x1c): undefined reference to llvm::PrettyStackTraceEntry::PrettyStackTraceEntry()' HSAILAsm.cpp:(.text._ZN4llvm23PrettyStackTraceProgramC2EiPKPKc[_ZN4llvm23PrettyStackTraceProgramC5EiPKPKc]+0x21): undefined reference tovtable for llvm::PrettyStackTraceProgram'
HSAILAsm.cpp:(.text._ZN4llvm23PrettyStackTraceProgramC2EiPKPKc[_ZN4llvm23PrettyStackTraceProgramC5EiPKPKc]+0x43): undefined reference to llvm::EnablePrettyStackTrace()' HSAILAsm.cpp:(.text._ZN4llvm23PrettyStackTraceProgramC2EiPKPKc[_ZN4llvm23PrettyStackTraceProgramC5EiPKPKc]+0x54): undefined reference tollvm::PrettyStackTraceEntry::~PrettyStackTraceEntry()'
CMakeFiles/HSAILasm.dir/HSAILAsm.cpp.o: In function llvm::PrettyStackTraceProgram::~PrettyStackTraceProgram()': HSAILAsm.cpp:(.text._ZN4llvm23PrettyStackTraceProgramD2Ev[_ZN4llvm23PrettyStackTraceProgramD5Ev]+0xd): undefined reference tovtable for llvm::PrettyStackTraceProgram'
HSAILAsm.cpp:(.text._ZN4llvm23PrettyStackTraceProgramD2Ev[_ZN4llvm23PrettyStackTraceProgramD5Ev]+0x20): undefined reference to `llvm::PrettyStackTraceEntry::~PrettyStackTraceEntry()'
collect2: error: ld returned 1 exit status

Asserts with -g

Assembling simple hsail files with the -g option yields an assert for me. For example:

$ cat fcos.hsail
//===- fcos.hsail ---------------------------------------------------------===//
//
// The HSA Simulator
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

version 0:96:$full:$small;

//==========================================================
// Function: __Get_fcos
//
// Inputs: arg_val0 - List of values to compute the fcos on
//
// Outputs: arg_val1 - Results
//
//==========================================================

kernel &__Get_fcos(kernarg_u32 %arg_val0, kernarg_u32 %arg_val1)
{
// Use workitemaid to get the buffer offset
workitemabsid_u32 $s1, 0;
shl_u32 $s1, $s1, 2; // Get offset by Multiplying by 4 because
// that is the size of each value in the buffer

    // Compute Address of Input Value and store in $s0
    ld_kernarg_u32  $s0, [%arg_val0];
    add_u32  $s0, $s0, $s1;  // Add offset to Address

    // Compute Address of Output Value and store in $s3
    ld_kernarg_u32  $s3, [%arg_val1];
    add_u32  $s3, $s3, $s1;  // Add offset to Address

    // Execute Trig Opcode
    ld_f32 $s0, [$s0];
    ncos_f32 $s2, $s0;

    // Store Dispatch ID on Kernel Argument
    st_global_u32   $s2, [$s3] ;

    ret;

};

$ ./hsailasm fcos.hsail -o fcos.o -g
hsailasm: libBRIGdwarf/BrigDwarfGenerator.cpp:1332: void BrigDebug::BrigDwarfGenerator_impl::createDwarfElfSections(): Assertion `relType == __R_HSA_DWARF_32' failed.
0 hsailasm 0x0000000000529acb
1 hsailasm 0x0000000000529d48
2 hsailasm 0x00000000005297c4
3 libpthread.so.0 0x00002ba208e68340
4 libc.so.6 0x00002ba2098ccf79 gsignal + 57
5 libc.so.6 0x00002ba2098d0388 abort + 328
6 libc.so.6 0x00002ba2098c5e36
7 libc.so.6 0x00002ba2098c5ee2
8 hsailasm 0x00000000004133c0
9 hsailasm 0x0000000000410afc
10 hsailasm 0x0000000000407adf
11 hsailasm 0x0000000000408065
12 hsailasm 0x0000000000408278
13 libc.so.6 0x00002ba2098b7ec5 __libc_start_main + 245
14 hsailasm 0x0000000000407199

Error: Invalid libHSAIL option when using -g option

Dear developer,

In the system requirements of HSA-Debugger, it states that the HSAIL applications must be built with HSAIL-Tools.

Thus, I built the HSAILasm successfully with the option BUILD_LIBBRIGDWARF and BUILD_HSAILASM.

However, when I execute HSAILasm -assemble -g matrixMul_kernel.hsail, it states that
Error: Invalid libHSAIL option: matrixMul_kernel.hsail. The -help option states that Usage: HSAILAsm [-assemble|-disassemble|-decode|-version|-help] [options] [input file].

Is there anything that I missed so far?

Thanks.

ELF format selection

Hi,

The current -elf64 flag will emit an ELF32 file.

Here's a simple patch for it, please take a look.

https://github.com/HSAFoundation/HSAIL-Tools/blob/master/libHSAIL%2FlibHSAIL%2FHSAILBrigObjectFile.cpp#L989

int BrigIO::save(BrigContainer &src,
                 int           fmt,
                 WriteAdapter& dst)
{
    if (fmt == FILE_FORMAT_BRIG) {
        return src.write(dst) ? 0 : 1;
    } 
+    if (fmt == FILE_FORMAT_ELF64) {
+    BrigIOImpl<Elf64Policy> impl(fmt);
-    BrigIOImpl<Elf32Policy> impl(fmt);
    return impl.writeContainer(&dst, src);
+ }
+   else  {
+    BrigIOImpl<Elf32Policy> impl(fmt);
+    return impl.writeContainer(&dst, src);
+ }

}

Also, the corresponding enumerators in HSAILBrigObjectFile.h should be fixed.

The cmake does not check for presence of libtinfo

If the user does not have libtinfo installed, the linking phase will
phase with a "cannot find -ltinfo: error. The cmake utility you use
instead of configure script should check check for it before
compilation.

Also, it would be nice to include in the README file among other
dependencies, on my system (OpenSUSE) it comes from package
ncurses-devel.

Error when compiling HSAIL-Tools

I have the following issue when compiling the code. Can anyone help me with that?

/home/yifan/hsa/HSAIL-Tools/libHSAIL/libHSAIL/BrigDwarfGenerator.cpp: In member function ‘void BrigDebug::BrigDwarfGenerator_impl::initializeDwarfProducer()’:
/home/yifan/hsa/HSAIL-Tools/libHSAIL/libHSAIL/BrigDwarfGenerator.cpp:515:50: error: invalid conversion from ‘int (*)(const char*, int, Dwarf_Unsigned, Dwarf_Unsigned, Dwarf_Unsigned, Dwarf_Unsigned, Dwarf_Unsigned*, void*, int*) {aka int (*)(const char*, int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int*, void*, int*)}’ to ‘Dwarf_Callback_Func {aka int (*)(char*, int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, int*, int*)}’ [-fpermissive]
                                            &pErr );
                                                  ^
/home/yifan/hsa/HSAIL-Tools/libHSAIL/libHSAIL/BrigDwarfGenerator.cpp:515:50: error: cannot convert ‘BrigDebug::BrigDwarfGenerator_impl*’ to ‘Dwarf_Error_s**’ for argument ‘5’ to ‘Dwarf_P_Debug_s* dwarf_producer_init(Dwarf_Unsigned, Dwarf_Callback_Func, Dwarf_Handler, Dwarf_Ptr, Dwarf_Error_s**)’

Ubuntu - HSAILasm link error

On Ubuntu with LLVM 3.4 (default llvm package), the HSAILasm binary will fail to link due to missing symbols such as setupterm, tigetnum, set_curterm...
It will only work if linking in libtinfo

ELF loader doesn't like ELF64

As the subject says. The ELF loader in libHSAIL currently recognizes and works
with only ELF32 objects. We're working on GCC emitting HSAIL, and we emit BRIG
into the respective .brig* sections, together with the normal host code, all
in one ELF file. Currently for testing/developing we need to use -m32 for everything
because of this issue. Would be nice if that would be extended. As the ELF file
effectively is just a random container format for the brig blobs those don't really
depend on the ELF format.

Same for the check on the e_machine ELF header member. Currently
the loader checks for it being EM_HSAIL_ (and non-agreed upon ELF
architecture), without any reasons to do so; the brig sections can just as
well come out of x86_64 or ppc ELF files.

Divergence between libHSAIL and HSA spec: brig section names

We're working with HSA PRM v0.95. It states the BRIG section names (19.1.1) are:

  .string
  .directive
  .code
  .operand
  .debug

As these names are fairly broad it makes sense that when included in ELF
files, that they be prepended with ".brig_". But libHSAIL goes further and
actually modifies these names, and it does so for the spec'ed names and
the prefixed ones. In particular it uses these names (from HSAILBrigObjectFile.cpp):

.directives .brig_directives
.code       .brig_code
.operands   .brig_operands
.debug      .brig_debug
.strtab     .brig_strtab

Note how libHSAIL uses plural form, while the spec uses singular. The name
for the string section is completely off, (.string vs. .strtab). As the BRIG
string section is used for arbitrary strings and byte blobs, and not only
for symbols it should not be named anything with strtab, as that's the
customary names for the string sections connected with ELF symbol
tables. So the spec'ed name .string makes the most sense.

In any case, either the spec or libHSAIL need fixing before it creeps into
all HSAIL producers and consumers.

Array Length Inconsistency

The HSA PRM 19.6.19 says,

If the symbol is an array with a size, then dim must be the number of elements in the array. If the symbol is not an array or is a flexible array, then dim must be 0. An array declared in the textual form without a size, but with an initializer, is not considered a flexible array. In this case, the value of dim is related to the directive referenced by the init field: if BrigDirectiveVariableInit, then dim must be the same value as elementCount field of the BrigDirectiveVariableInit; if BrigDirectiveImageInit or BrigDirectiveSamplerInit, then dim must be 1 because HSAIL allows only a single initializer for image and sampler objects.

But for the example:
global_u32 &array[10] = {1,2,3,4,5,6,7,8};

hsailasm sets dim to 10 and elementCount to 8.

Regarding arrays, HSA PRM 4.19.1 says,

If there is no initializer, the value of the object is undefined. However, if some of the elements are initialized, then the rest are initialized to zero.

make fails with ....

error: ‘*’ in boolean context, suggest ‘&&’ instead [-Werror=int-in-bool-context]

How dead is this project anyway ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.