endif (GBE_COMPILE_UTESTS)
install (TARGETS gbe LIBRARY DESTINATION lib)
-install (FILES gbe_program.h DESTINATION include/gen)
+install (FILES backend/gbe_program.h DESTINATION include/gen)
*/
#include "gbe_program.h"
+#include "gbe_program.hpp"
#include "gen/program.h"
#include "sim/program.h"
#include "sys/platform.hpp"
+#include "ir/liveness.hpp"
+#include "ir/value.hpp"
+#include "ir/unit.hpp"
+#include "llvm/llvm_to_gen.hpp"
#include <cstring>
-GBE_EXPORT_SYMBOL GBEProgramNewFromSourceCB *GBEProgramNewFromSource = NULL;
-GBE_EXPORT_SYMBOL GBEProgramNewFromBinaryCB *GBEProgramNewFromBinary = NULL;
-GBE_EXPORT_SYMBOL GBEProgramNewFromLLVMCB *GBEProgramNewFromLLVM = NULL;
-GBE_EXPORT_SYMBOL GBEProgramDeleteCB *GBEProgramDelete = NULL;
-GBE_EXPORT_SYMBOL GBEProgramGetKernelNumCB *GBEProgramGetKernelNum = NULL;
-GBE_EXPORT_SYMBOL GBEProgramGetKernelByNameCB *GBEProgramGetKernelByName = NULL;
-GBE_EXPORT_SYMBOL GBEProgramGetKernelCB *GBEProgramGetKernel = NULL;
-GBE_EXPORT_SYMBOL GBEKernelGetNameCB *GBEKernelGetName = NULL;
-GBE_EXPORT_SYMBOL GBEKernelGetCodeCB *GBEKernelGetCode = NULL;
-GBE_EXPORT_SYMBOL GBEKernelGetCodeSizeCB *GBEKernelGetCodeSize = NULL;
-GBE_EXPORT_SYMBOL GBEKernelGetArgNumCB *GBEKernelGetArgNum = NULL;
-GBE_EXPORT_SYMBOL GBEKernelGetArgSizeCB *GBEKernelGetArgSize = NULL;
-GBE_EXPORT_SYMBOL GBEKernelGetArgTypeCB *GBEKernelGetArgType = NULL;
-GBE_EXPORT_SYMBOL GBEKernelGetSIMDWidthCB *GBEKernelGetSIMDWidth = NULL;
-GBE_EXPORT_SYMBOL GBEKernelGetRequiredWorkGroupSizeCB *GBEKernelGetRequiredWorkGroupSize = NULL;
+namespace gbe {
+
+ Kernel::Kernel(const std::string &name) :
+ name(name), args(NULL), argNum(0), liveness(NULL), dag(NULL)
+ {}
+ Kernel::~Kernel(void) {
+ GBE_SAFE_DELETE_ARRAY(args);
+ GBE_SAFE_DELETE(liveness);
+ GBE_SAFE_DELETE(dag);
+ }
+
+ Program::Program(void) {}
+ Program::~Program(void) {
+ for (auto it = kernels.begin(); it != kernels.end(); ++it)
+ GBE_DELETE(it->second);
+ }
+
+ bool Program::buildFromLLVMFile(const char *fileName, std::string &error) {
+ ir::Unit unit;
+ if (llvmToGen(unit, fileName) == false) {
+ error = std::string(fileName) + " not found";
+ return false;
+ }
+ this->buildFromUnit(unit, error);
+ return true;
+ }
+
+ bool Program::buildFromUnit(const ir::Unit &unit, std::string &error) {
+ const auto &set = unit.getFunctionSet();
+ const uint32_t kernelNum = set.size();
+ if (kernelNum == 0) return true;
+
+ // Dummy functions now
+ for (auto it = set.begin(); it != set.end(); ++it) {
+ const std::string &name = it->first;
+ Kernel *kernel = this->compileKernel(name);
+ kernels.insert(std::make_pair(name, kernel));
+ }
+
+ return true;
+ }
+
+} /* namespace gbe */
+
+/////////////////////////////////////////////////////////////////////////////
+// Common C interface for both Gen and simulator
+/////////////////////////////////////////////////////////////////////////////
+static void GBEProgramDelete(gbe_program gbeProgram) {
+ gbe::Program *program = (gbe::Program*)(gbeProgram);
+ GBE_SAFE_DELETE(program);
+}
+
+static uint32_t GBEProgramGetKernelNum(gbe_program gbeProgram) {
+ if (gbeProgram == NULL) return 0;
+ const gbe::Program *program = (const gbe::Program*) gbeProgram;
+ return program->getKernelNum();
+}
+
+static gbe_kernel GBEProgramGetKernelByName(gbe_program gbeProgram, const char *name) {
+ if (gbeProgram == NULL) return NULL;
+ const gbe::Program *program = (gbe::Program*) gbeProgram;
+ return (gbe_kernel) program->getKernel(std::string(name));
+}
+
+static gbe_kernel GBEProgramGetKernel(const gbe_program gbeProgram, uint32_t ID) {
+ if (gbeProgram == NULL) return NULL;
+ const gbe::Program *program = (gbe::Program*) gbeProgram;
+ return (gbe_kernel) program->getKernel(ID);
+}
+
+static const char *GBEKernelGetName(gbe_kernel genKernel) {
+ if (genKernel == NULL) return NULL;
+ const gbe::Kernel *kernel = (const gbe::Kernel*) genKernel;
+ return kernel->getName();
+}
+
+static const char *GBEKernelGetCode(gbe_kernel genKernel) {
+ if (genKernel == NULL) return NULL;
+ const gbe::Kernel *kernel = (const gbe::Kernel*) genKernel;
+ return kernel->getCode();
+}
+
+static size_t GBEKernelGetCodeSize(gbe_kernel genKernel) {
+ if (genKernel == NULL) return 0u;
+ const gbe::Kernel *kernel = (const gbe::Kernel*) genKernel;
+ return kernel->getCodeSize();
+}
+
+static uint32_t GBEKernelGetArgNum(gbe_kernel genKernel) {
+ if (genKernel == NULL) return 0u;
+ const gbe::Kernel *kernel = (const gbe::Kernel*) genKernel;
+ return kernel->getArgNum();
+}
+
+static uint32_t GBEKernelGetArgSize(gbe_kernel genKernel, uint32_t argID) {
+ if (genKernel == NULL) return 0u;
+ const gbe::Kernel *kernel = (const gbe::Kernel*) genKernel;
+ return kernel->getArgSize(argID);
+}
+
+static gbe_arg_type GBEKernelGetArgType(gbe_kernel genKernel, uint32_t argID) {
+ if (genKernel == NULL) return GBE_ARG_INVALID;
+ const gbe::Kernel *kernel = (const gbe::Kernel*) genKernel;
+ return kernel->getArgType(argID);
+}
+
+static uint32_t GBEKernelGetSIMDWidth(gbe_kernel kernel) {
+ return 16u;
+}
+
+static uint32_t GBEKernelGetRequiredWorkGroupSize(gbe_kernel kernel, uint32_t dim) {
+ return 0u;
+}
+
+GBE_EXPORT_SYMBOL gbe_program_new_from_source_cb *gbe_program_new_from_source = NULL;
+GBE_EXPORT_SYMBOL gbe_program_new_from_binary_cb *gbe_program_new_from_binary = NULL;
+GBE_EXPORT_SYMBOL gbe_program_new_from_llvm_cb *gbe_program_new_from_llvm = NULL;
+GBE_EXPORT_SYMBOL gbe_program_delete_cb *gbe_program_delete = NULL;
+GBE_EXPORT_SYMBOL gbe_program_get_kernel_num_cb *gbe_program_get_kernel_num = NULL;
+GBE_EXPORT_SYMBOL gbe_program_get_kernel_by_name_cb *gbe_program_get_kernel_by_name = NULL;
+GBE_EXPORT_SYMBOL gbe_program_get_kernel_cb *gbe_program_get_kernel = NULL;
+GBE_EXPORT_SYMBOL gbe_kernel_get_name_cb *gbe_kernel_get_name = NULL;
+GBE_EXPORT_SYMBOL gbe_kernel_get_code_cb *gbe_kernel_get_code = NULL;
+GBE_EXPORT_SYMBOL gbe_kernel_get_code_size_cb *gbe_kernel_get_code_size = NULL;
+GBE_EXPORT_SYMBOL gbe_kernel_get_arg_num_cb *gbe_kernel_get_arg_num = NULL;
+GBE_EXPORT_SYMBOL gbe_kernel_get_arg_size_cb *gbe_kernel_get_arg_size = NULL;
+GBE_EXPORT_SYMBOL gbe_kernel_get_arg_type_cb *gbe_kernel_get_arg_type = NULL;
+GBE_EXPORT_SYMBOL gbe_kernel_get_simd_width_cb *gbe_kernel_get_simd_width = NULL;
+GBE_EXPORT_SYMBOL gbe_kernel_get_required_work_group_size_cb *gbe_kernel_get_required_work_group_size = NULL;
/* Use pre-main to setup the call backs */
struct CallBackInitializer
{
CallBackInitializer(void) {
+ gbe_program_delete = GBEProgramDelete;
+ gbe_program_get_kernel_num = GBEProgramGetKernelNum;
+ gbe_program_get_kernel_by_name = GBEProgramGetKernelByName;
+ gbe_program_get_kernel = GBEProgramGetKernel;
+ gbe_kernel_get_name = GBEKernelGetName;
+ gbe_kernel_get_code = GBEKernelGetCode;
+ gbe_kernel_get_code_size = GBEKernelGetCodeSize;
+ gbe_kernel_get_arg_num = GBEKernelGetArgNum;
+ gbe_kernel_get_arg_size = GBEKernelGetArgSize;
+ gbe_kernel_get_arg_type = GBEKernelGetArgType;
+ gbe_kernel_get_simd_width = GBEKernelGetSIMDWidth;
+ gbe_kernel_get_required_work_group_size = GBEKernelGetRequiredWorkGroupSize;
const char *run_it = getenv("OCL_SIMULATOR");
if (run_it != NULL && !strcmp(run_it, "2"))
- SimSetupCallBacks();
+ simSetupCallBacks();
else
- GenSetupCallBacks();
+ genSetupCallBacks();
}
};
#endif /* __cplusplus */
/*! Opaque structure that interfaces a GBE program */
-typedef struct GBEProgram GBEProgram;
+typedef struct _gbe_program *gbe_program;
/*! Opaque structure that interfaces a GBE kernel (ie one OCL function) */
-typedef struct GBEKernel GBEKernel;
+typedef struct _gbe_kernel *gbe_kernel;
/*! Argument type for each function call */
-enum GBEArgType {
- GEN_ARG_VALUE = 0, // int, float and so on
- GEN_ARG_GLOBAL_PTR = 1, // __global, __constant
- GEN_ARG_STRUCTURE = 2, // By value structure
- GEN_ARG_IMAGE = 3, // image2d_t, image3d_t
- GEN_ARG_INVALID = 0xffffffff
+enum gbe_arg_type {
+ GBE_ARG_VALUE = 0, // int, float and so on
+ GBE_ARG_GLOBAL_PTR = 1, // __global, __constant
+ GBE_ARG_STRUCTURE = 2, // By value structure
+ GBE_ARG_IMAGE = 3, // image2d_t, image3d_t
+ GBE_ARG_INVALID = 0xffffffff
};
/*! Create a new program from the given source code (zero terminated string) */
-typedef GBEProgram *(GBEProgramNewFromSourceCB)(const char *source);
-extern GBEProgramNewFromSourceCB *GBEProgramNewFromSource;
+typedef gbe_program (gbe_program_new_from_source_cb)(const char *source);
+extern gbe_program_new_from_source_cb *gbe_program_new_from_source;
/*! Create a new program from the given blob */
-typedef GBEProgram *(GBEProgramNewFromBinaryCB)(const char *binary, size_t size);
-extern GBEProgramNewFromBinaryCB *GBEProgramNewFromBinary;
+typedef gbe_program (gbe_program_new_from_binary_cb)(const char *binary, size_t size);
+extern gbe_program_new_from_binary_cb *gbe_program_new_from_binary;
/*! Create a new program from the given LLVM file */
-typedef GBEProgram *(GBEProgramNewFromLLVMCB)(const char *fileName,
- size_t stringSize,
- char *err,
- size_t *errSize);
-extern GBEProgramNewFromLLVMCB *GBEProgramNewFromLLVM;
+typedef gbe_program (gbe_program_new_from_llvm_cb)(const char *fileName,
+ size_t string_size,
+ char *err,
+ size_t *err_size);
+extern gbe_program_new_from_llvm_cb *gbe_program_new_from_llvm;
/*! Destroy and deallocate the given program */
-typedef void (GBEProgramDeleteCB)(GBEProgram*);
-extern GBEProgramDeleteCB *GBEProgramDelete;
+typedef void (gbe_program_delete_cb)(gbe_program);
+extern gbe_program_delete_cb *gbe_program_delete;
/*! Get the number of functions in the program */
-typedef uint32_t (GBEProgramGetKernelNumCB)(const GBEProgram*);
-extern GBEProgramGetKernelNumCB *GBEProgramGetKernelNum;
+typedef uint32_t (gbe_program_get_kernel_num_cb)(gbe_program);
+extern gbe_program_get_kernel_num_cb *gbe_program_get_kernel_num;
/*! Get the kernel from its name */
-typedef const GBEKernel *(GBEProgramGetKernelByNameCB)(const GBEProgram*, const char *name);
-extern GBEProgramGetKernelByNameCB *GBEProgramGetKernelByName;
+typedef gbe_kernel (gbe_program_get_kernel_by_name_cb)(gbe_program, const char *name);
+extern gbe_program_get_kernel_by_name_cb *gbe_program_get_kernel_by_name;
/*! Get the kernel from its ID */
-typedef const GBEKernel *(GBEProgramGetKernelCB)(const GBEProgram*, uint32_t ID);
-extern GBEProgramGetKernelCB *GBEProgramGetKernel;
+typedef gbe_kernel (gbe_program_get_kernel_cb)(gbe_program, uint32_t ID);
+extern gbe_program_get_kernel_cb *gbe_program_get_kernel;
/*! Get the GBE kernel name */
-typedef const char *(GBEKernelGetNameCB)(const GBEKernel*);
-extern GBEKernelGetNameCB *GBEKernelGetName;
+typedef const char *(gbe_kernel_get_name_cb)(gbe_kernel);
+extern gbe_kernel_get_name_cb *gbe_kernel_get_name;
/*! Get the GBE kernel source code */
-typedef const char *(GBEKernelGetCodeCB)(const GBEKernel*);
-extern GBEKernelGetCodeCB *GBEKernelGetCode;
+typedef const char *(gbe_kernel_get_code_cb)(gbe_kernel);
+extern gbe_kernel_get_code_cb *gbe_kernel_get_code;
/*! Get the size of the source code */
-typedef const size_t (GBEKernelGetCodeSizeCB)(const GBEKernel*);
-extern GBEKernelGetCodeSizeCB *GBEKernelGetCodeSize;
+typedef size_t (gbe_kernel_get_code_size_cb)(gbe_kernel);
+extern gbe_kernel_get_code_size_cb *gbe_kernel_get_code_size;
/*! Get the total number of arguments */
-typedef uint32_t (GBEKernelGetArgNumCB)(const GBEKernel*);
-extern GBEKernelGetArgNumCB *GBEKernelGetArgNum;
+typedef uint32_t (gbe_kernel_get_arg_num_cb)(gbe_kernel);
+extern gbe_kernel_get_arg_num_cb *gbe_kernel_get_arg_num;
/*! Get the size of the given argument */
-typedef uint32_t (GBEKernelGetArgSizeCB)(const GBEKernel*, uint32_t argID);
-extern GBEKernelGetArgSizeCB *GBEKernelGetArgSize;
+typedef uint32_t (gbe_kernel_get_arg_size_cb)(gbe_kernel, uint32_t argID);
+extern gbe_kernel_get_arg_size_cb *gbe_kernel_get_arg_size;
/*! Get the type of the given argument */
-typedef enum GBEArgType (GBEKernelGetArgTypeCB)(const GBEKernel*, uint32_t argID);
-extern GBEKernelGetArgTypeCB *GBEKernelGetArgType;
+typedef enum gbe_arg_type (gbe_kernel_get_arg_type_cb)(gbe_kernel, uint32_t argID);
+extern gbe_kernel_get_arg_type_cb *gbe_kernel_get_arg_type;
/*! Get the simd width for the kernel */
-typedef uint32_t (GBEKernelGetSIMDWidthCB)(const GBEKernel*);
-extern GBEKernelGetSIMDWidthCB *GBEKernelGetSIMDWidth;
+typedef uint32_t (gbe_kernel_get_simd_width_cb)(gbe_kernel);
+extern gbe_kernel_get_simd_width_cb *gbe_kernel_get_simd_width;
/*! Indicates if a work group size is required. Return the required width or 0
* if none
*/
-typedef uint32_t (GBEKernelGetRequiredWorkGroupSizeCB)(const GBEKernel*, uint32_t dim);
-extern GBEKernelGetRequiredWorkGroupSizeCB *GBEKernelGetRequiredWorkGroupSize;
+typedef uint32_t (gbe_kernel_get_required_work_group_size_cb)(gbe_kernel, uint32_t dim);
+extern gbe_kernel_get_required_work_group_size_cb *gbe_kernel_get_required_work_group_size;
#ifdef __cplusplus
}
namespace gbe {
namespace gen {
- Kernel::Kernel(const std::string &name) :
- name(name), args(NULL), insns(NULL), argNum(0), insnNum(0), liveness(NULL), dag(NULL)
+ GenKernel::GenKernel(const std::string &name) :
+ Kernel(name), insns(NULL), insnNum(0)
{}
- Kernel::~Kernel(void) {
- GBE_SAFE_DELETE_ARRAY(insns);
- GBE_SAFE_DELETE_ARRAY(args);
- GBE_SAFE_DELETE(liveness);
- GBE_SAFE_DELETE(dag);
- }
-
- Program::Program(void) {}
- Program::~Program(void) {
- for (auto it = kernels.begin(); it != kernels.end(); ++it)
- GBE_DELETE(it->second);
- }
-
- bool Program::buildFromSource(const char *source, std::string &error) {
- NOT_IMPLEMENTED;
- return false;
- }
-
- bool Program::buildFromLLVMFile(const char *fileName, std::string &error) {
- ir::Unit unit;
- if (llvmToGen(unit, fileName) == false) {
- error = std::string(fileName) + " not found";
- return false;
- }
- this->buildFromUnit(unit, error);
- return true;
- }
-
- bool Program::buildFromUnit(const ir::Unit &unit, std::string &error) {
- const auto &set = unit.getFunctionSet();
- const uint32_t kernelNum = set.size();
- if (kernelNum == 0) return true;
-
- // Dummy functions now
- for (auto it = set.begin(); it != set.end(); ++it) {
- const std::string &name = it->first;
- // const ir::Function &fn = *it->second;
- Kernel *kernel = GBE_NEW(Kernel, name);
- brw_compile *p = (brw_compile*) GBE_MALLOC(sizeof(brw_compile));
- std::memset(p, 0, sizeof(*p));
- brw_EOT(p, 127);
- kernel->insnNum = p->nr_insn;
- kernel->insns = GBE_NEW_ARRAY(brw_instruction, kernel->insnNum);
- std::memcpy(kernel->insns, p->store, kernel->insnNum * sizeof(brw_instruction));
- GBE_FREE(p);
- kernels.insert(std::make_pair(name, kernel));
- }
-
- return true;
+ GenKernel::~GenKernel(void) { GBE_SAFE_DELETE_ARRAY(insns); }
+
+ GenProgram::GenProgram(void) {}
+ GenProgram::~GenProgram(void) {}
+
+ Kernel *GenProgram::compileKernel(const std::string &name) {
+ GenKernel *kernel = GBE_NEW(GenKernel, name);
+ brw_compile *p = (brw_compile*) GBE_MALLOC(sizeof(brw_compile));
+ std::memset(p, 0, sizeof(*p));
+ brw_EOT(p, 127);
+ kernel->insnNum = p->nr_insn;
+ kernel->insns = GBE_NEW_ARRAY(brw_instruction, kernel->insnNum);
+ std::memcpy(kernel->insns, p->store, kernel->insnNum * sizeof(brw_instruction));
+ GBE_FREE(p);
+ return kernel;
}
} /* namespace gen */
} /* namespace gbe */
/////////////////////////////////////////////////////////////////////////////
-// C interface for the Gen Programs
+// C interface for the specific Gen ISA compilation path
/////////////////////////////////////////////////////////////////////////////
-static
-GBEProgram *GenProgramNewFromSource(const char *source) {
+static gbe_program GenProgramNewFromSource(const char *source) {
NOT_IMPLEMENTED;
return NULL;
}
-static
-GBEProgram *GenProgramNewFromBinary(const char *binary, size_t size) {
+static gbe_program GenProgramNewFromBinary(const char *binary, size_t size) {
NOT_IMPLEMENTED;
return NULL;
}
-static
-GBEProgram *GenProgramNewFromLLVM(const char *fileName,
- size_t stringSize,
- char *err,
- size_t *errSize)
+static gbe_program GenProgramNewFromLLVM(const char *fileName,
+ size_t stringSize,
+ char *err,
+ size_t *errSize)
{
using namespace gbe::gen;
- Program *program = GBE_NEW(Program);
+ GenProgram *program = GBE_NEW(GenProgram);
std::string error;
// Try to compile the program
}
// Everything run fine
- return (GBEProgram *) program;
-}
-
-static
-void GenProgramDelete(GBEProgram *genProgram) {
- gbe::gen::Program *program = (gbe::gen::Program*)(genProgram);
- GBE_SAFE_DELETE(program);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// C interface for the Gen Kernels
-/////////////////////////////////////////////////////////////////////////////
-static uint32_t GenProgramGetKernelNum(const GBEProgram *genProgram) {
- if (genProgram == NULL) return 0;
- const gbe::gen::Program *program = (const gbe::gen::Program*) genProgram;
- return program->getKernelNum();
-}
-
-static const GBEKernel *GenProgramGetKernelByName(const GBEProgram *genProgram, const char *name) {
- if (genProgram == NULL) return NULL;
- const gbe::gen::Program *program = (const gbe::gen::Program*) genProgram;
- return (GBEKernel*) program->getKernel(std::string(name));
-}
-
-static const GBEKernel *GenProgramGetKernel(const GBEProgram *genProgram, uint32_t ID) {
- if (genProgram == NULL) return NULL;
- const gbe::gen::Program *program = (const gbe::gen::Program*) genProgram;
- return (GBEKernel*) program->getKernel(ID);
-}
-
-static const char *GenKernelGetName(const GBEKernel *genKernel) {
- if (genKernel == NULL) return NULL;
- const gbe::gen::Kernel *kernel = (const gbe::gen::Kernel*) genKernel;
- return kernel->getName();
-}
-
-static const char *GenKernelGetCode(const GBEKernel *genKernel) {
- if (genKernel == NULL) return NULL;
- const gbe::gen::Kernel *kernel = (const gbe::gen::Kernel*) genKernel;
- return kernel->getCode();
-}
-
-static const size_t GenKernelGetCodeSize(const GBEKernel *genKernel) {
- if (genKernel == NULL) return 0u;
- const gbe::gen::Kernel *kernel = (const gbe::gen::Kernel*) genKernel;
- return kernel->getCodeSize();
-}
-
-static uint32_t GenKernelGetArgNum(const GBEKernel *genKernel) {
- if (genKernel == NULL) return 0u;
- const gbe::gen::Kernel *kernel = (const gbe::gen::Kernel*) genKernel;
- return kernel->getArgNum();
-}
-
-static uint32_t GenKernelGetArgSize(const GBEKernel *genKernel, uint32_t argID) {
- if (genKernel == NULL) return 0u;
- const gbe::gen::Kernel *kernel = (const gbe::gen::Kernel*) genKernel;
- return kernel->getArgSize(argID);
-}
-
-static GBEArgType GenKernelGetArgType(const GBEKernel *genKernel, uint32_t argID) {
- if (genKernel == NULL) return GEN_ARG_INVALID;
- const gbe::gen::Kernel *kernel = (const gbe::gen::Kernel*) genKernel;
- return kernel->getArgType(argID);
-}
-
-static uint32_t GenKernelGetSIMDWidth(const GBEKernel *kernel) {
- return 16u;
-}
-
-static uint32_t GenKernelGetRequiredWorkGroupSize(const GBEKernel *kernel, uint32_t dim) {
- return 0u;
+ return (gbe_program) program;
}
-void GenSetupCallBacks(void)
+void genSetupCallBacks(void)
{
- GBEProgramNewFromSource = GenProgramNewFromSource;
- GBEProgramNewFromBinary = GenProgramNewFromBinary;
- GBEProgramNewFromLLVM = GenProgramNewFromLLVM;
- GBEProgramDelete = GenProgramDelete;
- GBEProgramGetKernelNum = GenProgramGetKernelNum;
- GBEProgramGetKernelByName = GenProgramGetKernelByName;
- GBEProgramGetKernel = GenProgramGetKernel;
- GBEKernelGetName = GenKernelGetName;
- GBEKernelGetCode = GenKernelGetCode;
- GBEKernelGetCodeSize = GenKernelGetCodeSize;
- GBEKernelGetArgNum = GenKernelGetArgNum;
- GBEKernelGetArgSize = GenKernelGetArgSize;
- GBEKernelGetArgType = GenKernelGetArgType;
- GBEKernelGetSIMDWidth = GenKernelGetSIMDWidth;
- GBEKernelGetRequiredWorkGroupSize = GenKernelGetRequiredWorkGroupSize;
+ gbe_program_new_from_source = GenProgramNewFromSource;
+ gbe_program_new_from_binary = GenProgramNewFromBinary;
+ gbe_program_new_from_llvm = GenProgramNewFromLLVM;
}
#include <stdlib.h>
/*! This will make the compiler output Gen ISA code */
-extern void GenSetupCallBacks(void);
+extern void genSetupCallBacks(void);
#endif /* __GBE_GEN_PROGRAM_H__ */
#define __GBE_GEN_PROGRAM_HPP__
#include "backend/gbe_program.h"
+#include "backend/gbe_program.hpp"
#include "backend/gen/brw_structs.h"
-#include "sys/hash_map.hpp"
-#include <string>
-
-namespace gbe {
-namespace ir {
-
- class Unit; // Compilation unit. Contains the program to compile
- class Liveness; // Describes liveness of each ir function register
- class FunctionDAG; // Describes the instruction dependencies
-
-} /* namespace ir */
-} /* namespace gbe */
namespace gbe {
namespace gen {
- struct KernelArgument {
- GBEArgType type; //!< Pointer, structure, regular value?
- size_t size; //!< Size of each argument
- };
-
/*! Describe a compiled kernel */
- struct Kernel : public NonCopyable
+ struct GenKernel : public Kernel
{
/*! Create an empty kernel with the given name */
- Kernel(const std::string &name);
+ GenKernel(const std::string &name);
/*! Destroy it */
- ~Kernel(void);
- /*! Return the instruction stream */
- INLINE const char *getCode(void) const { return (const char*) insns; }
- /*! Return the instruction stream size */
- INLINE size_t getCodeSize(void) const {
+ virtual ~GenKernel(void);
+ /*! Implements base class */
+ virtual const char *getCode(void) const { return (const char*) insns; }
+ /*! Implements base class */
+ virtual size_t getCodeSize(void) const {
return insnNum * sizeof(brw_instruction);
}
- /*! Get the kernel name */
- INLINE const char *getName(void) const { return name.c_str(); }
- /*! Return the number of arguments for the kernel call */
- INLINE uint32_t getArgNum(void) const { return argNum; }
- /*! Return the size of the given argument */
- INLINE uint32_t getArgSize(uint32_t argID) const {
- if (argID >= argNum)
- return 0u;
- else
- return args[argID].size;
- }
- /*! Return the type of the given argument */
- INLINE GBEArgType getArgType(uint32_t argID) const {
- if (argID >= argNum)
- return GEN_ARG_INVALID;
- else
- return args[argID].type;
- }
- private:
- friend class Program; //!< Owns the kernels
- const std::string name; //!< Kernel name
- KernelArgument *args; //!< Each argument
brw_instruction *insns; //!< Instruction stream
- uint32_t argNum; //!< Number of function arguments
uint32_t insnNum; //!< Number of instructions
- ir::Liveness *liveness; //!< Used only for the build
- ir::FunctionDAG *dag; //!< Used only for the build
- GBE_STRUCT(Kernel); //!< Use gbe allocators
+ GBE_STRUCT(GenKernel); //!< Use gbe allocators
};
/*! Describe a compiled program */
- struct Program : public NonCopyable
+ struct GenProgram : public Program
{
/*! Create an empty program */
- Program(void);
+ GenProgram(void);
/*! Destroy the program */
- ~Program(void);
- /*! Get the number of kernels in the program */
- uint32_t getKernelNum(void) const { return kernels.size(); }
- /*! Get the kernel from its name */
- Kernel *getKernel(const std::string &name) const {
- auto it = kernels.find(name);
- if (it == kernels.end())
- return NULL;
- else
- return it->second;
- }
- /*! Get the kernel from its ID */
- Kernel *getKernel(const uint32_t ID) const {
- uint32_t currID = 0;
- Kernel *kernel = NULL;
- for (auto it = kernels.begin(); it != kernels.end(); ++it) {
- if (currID == ID) {
- kernel = it->second;
- break;
- }
- }
- return kernel;
- }
- /*! Build a program from a ir::Unit */
- bool buildFromUnit(const ir::Unit &unit, std::string &error);
- /*! Buils a program from a LLVM source code */
- bool buildFromLLVMFile(const char *fileName, std::string &error);
- /*! Buils a program from a OCL string */
- bool buildFromSource(const char *source, std::string &error);
- private:
- /*! Kernels sorted by their name */
- hash_map<std::string, Kernel*> kernels;
+ virtual ~GenProgram(void);
+ /*! Implements base class */
+ Kernel *compileKernel(const std::string &name);
+ GBE_STRUCT(GenProgram); //!< Use gbe allocators
};
} /* namespace gen */
} /* namespace sim */
} /* namespace gen */
- void SimSetupCallBacks(void)
+ void simSetupCallBacks(void)
{
#if 0
GBEProgramNewFromSource = SimProgramNewFromSource;
#include <stdlib.h>
/*! This will make the compiler output Gen ISA code */
-extern void SimSetupCallBacks(void);
+extern void simSetupCallBacks(void);
#endif /* __GBE_SIM_PROGRAM_H__ */