///////////////////////////////////////////////////////////////////////////
GenContext::GenContext(const ir::Unit &unit,
const std::string &name,
+ uint32_t deviceID,
bool limitRegisterPressure,
bool relaxMath) :
- Context(unit, name), limitRegisterPressure(limitRegisterPressure), relaxMath(relaxMath)
+ Context(unit, name), deviceID(deviceID), limitRegisterPressure(limitRegisterPressure), relaxMath(relaxMath)
{
- this->p = GBE_NEW(GenEncoder, simdWidth, 7); // XXX handle more than Gen7
+ this->p = GBE_NEW(GenEncoder, simdWidth, 7, deviceID); // XXX handle more than Gen7
this->sel = GBE_NEW(Selection, *this);
this->ra = GBE_NEW(GenRegAllocator, *this);
}
/*! Create a new context. name is the name of the function we want to
* compile
*/
- GenContext(const ir::Unit &unit, const std::string &name, bool limitRegisterPressure = false, bool relaxMath = false);
+ GenContext(const ir::Unit &unit, const std::string &name, uint32_t deviceID, bool limitRegisterPressure = false, bool relaxMath = false);
/*! Release everything needed */
~GenContext(void);
+ /*! Target device ID*/
+ uint32_t deviceID;
/*! Implements base class */
virtual bool emitCode(void);
/*! Function we emit code for */
//////////////////////////////////////////////////////////////////////////
// Gen Emitter encoding class
//////////////////////////////////////////////////////////////////////////
- GenEncoder::GenEncoder(uint32_t simdWidth, uint32_t gen) :
- stateNum(0), gen(gen)
+ GenEncoder::GenEncoder(uint32_t simdWidth, uint32_t gen, uint32_t deviceID) :
+ stateNum(0), gen(gen), deviceID(deviceID)
{
this->curr.execWidth = simdWidth;
this->curr.quarterControl = GEN_COMPRESSION_Q1;
#include "sys/platform.hpp"
#include "sys/vector.hpp"
#include <cassert>
+#include "src/cl_device_data.h"
namespace gbe
{
{
public:
/*! simdWidth is the default width for the instructions */
- GenEncoder(uint32_t simdWidth, uint32_t gen);
+ GenEncoder(uint32_t simdWidth, uint32_t gen, uint32_t deviceID);
/*! Size of the stack (should be large enough) */
enum { MAX_STATE_NUM = 16 };
/*! Push the current instruction state */
uint32_t stateNum;
/*! Gen generation to encode */
uint32_t gen;
+ /*! Device ID */
+ uint32_t deviceID;
////////////////////////////////////////////////////////////////////////
// Encoding functions
fclose(f);
}
- GenProgram::GenProgram(void) {}
GenProgram::~GenProgram(void) {}
/*! We must avoid spilling at all cost with Gen */
// Force the SIMD width now and try to compile
unit.getFunction(name)->setSimdWidth(simdWidth);
- Context *ctx = GBE_NEW(GenContext, unit, name, limitRegisterPressure, relaxMath);
+ Context *ctx = GBE_NEW(GenContext, unit, name, deviceID, limitRegisterPressure, relaxMath);
kernel = ctx->compileKernel();
if (kernel != NULL) {
break;
return kernel;
}
- static gbe_program genProgramNewFromBinary(const char *binary, size_t size) {
+ static gbe_program genProgramNewFromBinary(uint32_t deviceID, const char *binary, size_t size) {
using namespace gbe;
std::string binary_content;
binary_content.assign(binary, size);
- GenProgram *program = GBE_NEW_NO_ARG(GenProgram);
+ GenProgram *program = GBE_NEW(GenProgram, deviceID);
std::istringstream ifs(binary_content, std::ostringstream::binary);
+ // FIXME we need to check the whether the current device ID match the binary file's.
+ deviceID = deviceID;
if (!program->deserializeFromBin(ifs)) {
delete program;
return sz;
}
- static gbe_program genProgramNewFromLLVM(const char *fileName,
+ static gbe_program genProgramNewFromLLVM(uint32_t deviceID,
+ const char *fileName,
size_t stringSize,
char *err,
size_t *errSize,
int optLevel)
{
using namespace gbe;
- GenProgram *program = GBE_NEW_NO_ARG(GenProgram);
+ GenProgram *program = GBE_NEW(GenProgram, deviceID);
std::string error;
// Try to compile the program
if (program->buildFromLLVMFile(fileName, error, optLevel) == false) {
{
public:
/*! Create an empty program */
- GenProgram(void);
+ GenProgram(uint32_t deviceID) : deviceID(deviceID) {}
+ /*! Current device ID*/
+ uint32_t deviceID;
/*! Destroy the program */
virtual ~GenProgram(void);
/*! Implements base class */
extern std::string ocl_stdlib_str;
BVAR(OCL_USE_PCH, true);
- static gbe_program programNewFromSource(const char *source,
+ static gbe_program programNewFromSource(uint32_t deviceID,
+ const char *source,
size_t stringSize,
const char *options,
char *err,
err += *errSize;
clangErrSize = *errSize;
}
- p = gbe_program_new_from_llvm(llName.c_str(), stringSize,
+ p = gbe_program_new_from_llvm(deviceID, llName.c_str(), stringSize,
err, errSize, optLevel);
if (err != NULL)
*errSize += clangErrSize;
extern gbe_kernel_get_image_data_cb *gbe_kernel_get_image_data;
/*! Create a new program from the given source code (zero terminated string) */
-typedef gbe_program (gbe_program_new_from_source_cb)(const char *source,
+typedef gbe_program (gbe_program_new_from_source_cb)(uint32_t deviceID,
+ const char *source,
size_t stringSize,
const char *options,
char *err,
extern gbe_program_new_from_source_cb *gbe_program_new_from_source;
/*! Create a new program from the given blob */
-typedef gbe_program (gbe_program_new_from_binary_cb)(const char *binary, size_t size);
+typedef gbe_program (gbe_program_new_from_binary_cb)(uint32_t deviceID, const char *binary, size_t size);
extern gbe_program_new_from_binary_cb *gbe_program_new_from_binary;
/*! Serialize a program to a bin */
extern gbe_program_serialize_to_binary_cb *gbe_program_serialize_to_binary;
/*! Create a new program from the given LLVM file */
-typedef gbe_program (gbe_program_new_from_llvm_cb)(const char *fileName,
+typedef gbe_program (gbe_program_new_from_llvm_cb)(uint32_t deviceID,
+ const char *fileName,
size_t string_size,
char *err,
size_t *err_size,
void program_build_instance::build_program(void) throw(int)
{
- gbe_program opaque = gbe_program_new_from_source(code, 0, build_opt.c_str(), NULL, NULL);
+ // FIXME, we need to find a graceful way to generate internal binaries for difference
+ // devices.
+ gbe_program opaque = gbe_program_new_from_source(0, code, 0, build_opt.c_str(), NULL, NULL);
if (!opaque)
throw FILE_BUILD_FAILED;
INVALID_VALUE_IF (file_name == NULL);
program = cl_program_new(ctx);
- program->opaque = gbe_program_new_from_llvm(file_name, program->build_log_max_sz, program->build_log, &program->build_log_sz, 1);
+ program->opaque = gbe_program_new_from_llvm(ctx->device->vendor_id, file_name, program->build_log_max_sz, program->build_log, &program->build_log_sz, 1);
if (UNLIKELY(program->opaque == NULL)) {
err = CL_INVALID_PROGRAM;
goto error;
}
if (p->source_type == FROM_SOURCE) {
- p->opaque = gbe_program_new_from_source(p->source, p->build_log_max_sz, options, p->build_log, &p->build_log_sz);
+ p->opaque = gbe_program_new_from_source(p->ctx->device->vendor_id, p->source, p->build_log_max_sz, options, p->build_log, &p->build_log_sz);
if (UNLIKELY(p->opaque == NULL)) {
if (p->build_log_sz > 0 && strstr(p->build_log, "error: error reading 'options'"))
err = CL_INVALID_BUILD_OPTIONS;
TRY (cl_program_load_gen_program, p);
p->source_type = FROM_LLVM;
} else if (p->source_type == FROM_BINARY) {
- p->opaque = gbe_program_new_from_binary(p->binary, p->binary_sz);
+ p->opaque = gbe_program_new_from_binary(p->ctx->device->vendor_id, p->binary, p->binary_sz);
if (UNLIKELY(p->opaque == NULL)) {
err = CL_BUILD_PROGRAM_FAILURE;
goto error;