ECR #333755 - Add helper files to load Hsail Text files and assembled them into Brig files.

[git-p4: depot-paths = "//depot/stg/hsa/drivers/hsa/runtime/": change = 1127109]


[ROCm/ROCR-Runtime commit: 21449d717f]
Цей коміт міститься в:
Ramesh Errabolu (xN/A) TX
2015-03-03 19:41:56 -05:00
джерело dc0719196c
коміт 88c0ffb11e
7 змінених файлів з 320 додано та 0 видалено
+7
Переглянути файл
@@ -0,0 +1,7 @@
OPENCL_DEPTH = ../../..
include $(OPENCL_DEPTH)/runtimenew/runtimedefs
SUBDIRS = build
include $(OPENCL_DEPTH)/runtimenew/runtimerules
+147
Переглянути файл
@@ -0,0 +1,147 @@
#include <cassert>
#include <cstdint>
#include <fstream>
#include <new>
#include <sstream>
#include <string>
#include <unordered_map>
#include <utility>
#include "assemble.hpp"
#include "hsa.h"
#include "hsa_ext_alt_finalize.h"
#include "HSAILDisassembler.h"
#include "HSAILParser.h"
#include "HSAILScanner.h"
#include "HSAILValidator.h"
namespace {
std::unordered_map<uint64_t, uint64_t> mod2con;
} // namespace anonymous
hsa_status_t ModuleCreateFromHsailTextFile(
const char *hsail_text_filename,
hsa_ext_alt_module_t *module
) {
if (!hsail_text_filename) {
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
}
std::ifstream hsail_text_file(hsail_text_filename);
if (!hsail_text_file.is_open()) {
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
}
std::string hsail_string;
hsail_text_file.seekg(0, std::ios::end);
hsail_string.resize(hsail_text_file.tellg());
hsail_text_file.seekg(0, std::ios::beg);
hsail_text_file.read(&hsail_string[0], hsail_string.size());
hsail_text_file.close();
return ModuleCreateFromHsailString(hsail_string.c_str(), module);
}
hsa_status_t ModuleCreateFromHsailString(
const char *hsail_string,
hsa_ext_alt_module_t *module
) {
if (!hsail_string || !module) {
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
}
HSAIL_ASM::BrigContainer *brig_container = NULL;
try {
brig_container = new HSAIL_ASM::BrigContainer;
} catch (const std::bad_alloc) {
return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
}
std::istringstream hsail_stream(hsail_string);
try {
HSAIL_ASM::Scanner hsail_scanner(hsail_stream);
HSAIL_ASM::Parser hsail_parser(hsail_scanner, *brig_container);
hsail_parser.parseSource();
} catch (const SyntaxError) {
delete brig_container;
return static_cast<hsa_status_t>(HSA_EXT_ALT_STATUS_ERROR_INVALID_MODULE);
}
try {
auto insert_status = mod2con.insert(
std::make_pair<uint64_t, uint64_t>(
reinterpret_cast<uint64_t>(brig_container->getBrigModule()),
reinterpret_cast<uint64_t>(brig_container)
)
);
assert(insert_status.second);
} catch (const std::bad_alloc) {
delete brig_container;
return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
}
module->handle = reinterpret_cast<uint64_t>(brig_container->getBrigModule());
return HSA_STATUS_SUCCESS;
}
hsa_status_t ModuleDestroy(
hsa_ext_alt_module_t module
) {
auto find_status = mod2con.find(module.handle);
if (find_status == mod2con.end()) {
return static_cast<hsa_status_t>(HSA_EXT_ALT_STATUS_ERROR_INVALID_MODULE);
}
HSAIL_ASM::BrigContainer *brig_container =
reinterpret_cast<HSAIL_ASM::BrigContainer*>(find_status->second);
assert(brig_container);
delete brig_container;
mod2con.erase(find_status);
return HSA_STATUS_SUCCESS;
}
hsa_status_t ModuleValidate(
hsa_ext_alt_module_t module,
uint32_t *result
) {
if (!result) {
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
}
auto find_status = mod2con.find(module.handle);
if (find_status == mod2con.end()) {
return static_cast<hsa_status_t>(HSA_EXT_ALT_STATUS_ERROR_INVALID_MODULE);
}
HSAIL_ASM::BrigContainer *brig_container =
reinterpret_cast<HSAIL_ASM::BrigContainer*>(find_status->second);
assert(brig_container);
HSAIL_ASM::Validator brig_validator(*brig_container);
*result = brig_validator.validate() ? 0 : 1;
return HSA_STATUS_SUCCESS;
}
hsa_status_t ModuleDisassemble(
hsa_ext_alt_module_t module,
const char *hsail_text_filename
) {
if (!hsail_text_filename) {
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
}
auto find_status = mod2con.find(module.handle);
if (find_status == mod2con.end()) {
return static_cast<hsa_status_t>(HSA_EXT_ALT_STATUS_ERROR_INVALID_MODULE);
}
HSAIL_ASM::BrigContainer *brig_container =
reinterpret_cast<HSAIL_ASM::BrigContainer*>(find_status->second);
assert(brig_container);
HSAIL_ASM::Disassembler brig_disassembler(*brig_container);
if (brig_disassembler.run(hsail_text_filename)) {
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
}
return HSA_STATUS_SUCCESS;
}
+32
Переглянути файл
@@ -0,0 +1,32 @@
#ifndef ASSEMBLE_HPP_
#define ASSEMBLE_HPP_
#include <cstdint>
#include "hsa.h"
#include "hsa_ext_alt_finalize.h"
hsa_status_t ModuleCreateFromHsailTextFile(
const char *hsail_text_filename,
hsa_ext_alt_module_t *module
);
hsa_status_t ModuleCreateFromHsailString(
const char *hsail_string,
hsa_ext_alt_module_t *module
);
hsa_status_t ModuleDestroy(
hsa_ext_alt_module_t module
);
hsa_status_t ModuleValidate(
hsa_ext_alt_module_t module,
uint32_t *result
);
hsa_status_t ModuleDisassemble(
hsa_ext_alt_module_t module,
const char *hsail_text_filename
);
#endif // ASSEMBLE_HPP_
+8
Переглянути файл
@@ -0,0 +1,8 @@
OPENCL_DEPTH = ../../../..
include $(OPENCL_DEPTH)/runtimenew/runtimedefs
BUILD_SUBDIRS = $(DEFAULT_TARGETS)
BUILD_MAKEFILE = Makefile.common
include $(OPENCL_DEPTH)/runtimenew/runtimerules
+51
Переглянути файл
@@ -0,0 +1,51 @@
include $(OPENCL_DEPTH)/hsadefs
LIB_TARGET = testcommon
vpath %.cpp $(COMPONENT_DEPTH)
CPPFILES := $(notdir $(wildcard $(COMPONENT_DEPTH)/*.cpp))
ifdef ATI_BITS_64
LIB_SUFFIX = 64
NBITS = 64
else
LIB_SUFFIX =
ifndef ATI_OS_WINDOWS
NBITS := 32
endif
endif
ifdef ATI_OS_WINDOWS
CORE_LIB = dll
LFLAGS += /subsystem:console
LIB_PREFIX =
else
CORE_LIB = so
LIB_PREFIX = lib
endif
ifdef ATI_OS_LINUX
GCXXOPTS := $(filter-out -fno-rtti,$(GCXXOPTS))
GCXXOPTS := $(filter-out -fno-exceptions,$(GCXXOPTS))
LFLAGS += -L$(DIST_LIB_DEST) -lpthread $(LIBSTDCXX) -lm -ldl -lrt
endif
export BUILD_HSA_TARGET=yes
LCINCS := $(INCSWITCH) "$(OPENCL_DEPTH)/compiler/finalizer/HSAIL/hsail-tools/libHSAIL"
LCINCS += $(INCSWITCH) "$(OPENCL_DEPTH)/compiler/finalizer/HSAIL/hsail-tools/libHSAIL/$(FULL_BUILD_DIR)"
LCINCS += $(INCSWITCH) "$(OPENCL_DEPTH)/compiler/finalizer/Interface"
LCINCS += $(INCSWITCH) "$(OPENCL_DEPTH)/runtime/inc"
LLLIBS := $(OPENCL_DEPTH)/compiler/finalizer/HSAIL/hsail-tools/libHSAIL/$(FULL_BUILD_DIR)/libhsail$(LIB_EXT)
LLLIBS += $(OPENCL_DEPTH)/contrib/gtest-1.6.0/$(FULL_BUILD_DIR)/libgtest$(LIB_EXT)
LLLIBS += $(OPENCL_DEPTH)/runtime/test/gcommon/$(FULL_BUILD_DIR)/gtestcommon$(LIB_EXT)
RUNTIME_BUILD = build/$(OS_TYPE)/$(CORE_LIB)/$(BUILD_DIR)
ifdef ATI_OS_LINUX
LFLAGS += -L$(OPENCL_DEPTH)/runtime/core/$(RUNTIME_BUILD) -lhsa-runtime$(LIB_SUFFIX)
else
LLLIBS += $(OPENCL_DEPTH)/runtime/core/$(RUNTIME_BUILD)/hsa-runtime$(LIB_SUFFIX)$(LIB_EXT)
endif
include $(OPENCL_DEPTH)/hsarules
+48
Переглянути файл
@@ -0,0 +1,48 @@
#include "common.hpp"
void ErrorCheck(hsa_status_t hsa_error_code) {
if (hsa_error_code != HSA_STATUS_SUCCESS) {
std::cerr << "HSA reported error!" << std::endl;
exit(EXIT_FAILURE);
}
}
hsa_status_t FindGpuDevice(hsa_agent_t agent, void *data) {
if (data == NULL) {
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
}
hsa_device_type_t hsa_device_type;
hsa_status_t hsa_error_code = hsa_agent_get_info(
agent, HSA_AGENT_INFO_DEVICE, &hsa_device_type
);
if (hsa_error_code != HSA_STATUS_SUCCESS) {
return hsa_error_code;
}
if (hsa_device_type == HSA_DEVICE_TYPE_GPU) {
*((hsa_agent_t*)data) = agent;
}
return HSA_STATUS_SUCCESS;
}
hsa_status_t FindHostRegion(hsa_region_t region, void *data) {
if (data == NULL) {
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
}
bool is_host_region = false;
hsa_status_t hsa_error_code = hsa_region_get_info(
region, (hsa_region_info_t)HSA_EXT_AMD_REGION_INFO_HOST_ACCESS,
&is_host_region);
if (hsa_error_code != HSA_STATUS_SUCCESS) {
return hsa_error_code;
}
if (is_host_region) {
*((hsa_region_t*)data) = region;
}
return HSA_STATUS_SUCCESS;
}
+27
Переглянути файл
@@ -0,0 +1,27 @@
#ifndef COMMON_COMMON_HPP
#define COMMON_COMMON_HPP
#include <cstdlib>
#include <iostream>
#include "hsa.h"
#include "hsa_ext_finalize.h"
#include "hsa_ext_amd.h"
#if defined(_MSC_VER)
#define ALIGNED_(x) __declspec(align(x))
#else
#if defined(__GNUC__)
#define ALIGNED_(x) __attribute__ ((aligned(x)))
#endif // __GNUC__
#endif // _MSC_VER
#define MULTILINE(...) # __VA_ARGS__
void ErrorCheck(hsa_status_t hsa_error_code);
hsa_status_t FindGpuDevice(hsa_agent_t agent, void *data);
hsa_status_t FindHostRegion(hsa_region_t region, void *data);
#endif // COMMON_COMMON_HPP