sys/condition.hpp
sys/platform.cpp
sys/platform.hpp
+ gbe_program.cpp
+ gbe_program.h
ir/context.cpp
ir/context.hpp
ir/profile.cpp
gen/program.h
gen/brw_disasm.c
gen/brw_eu_emit.c
- gen/brw_eu.c)
+ gen/brw_eu.c
+ sim/program.cpp
+ sim/program.h)
if (GBE_COMPILE_UTESTS)
set (GBE_SRC
endif (GBE_COMPILE_UTESTS)
install (TARGETS gbe LIBRARY DESTINATION lib)
-install (FILES gen/program.h DESTINATION include/gen)
+install (FILES gbe_program.h DESTINATION include/gen)
--- /dev/null
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+/**
+ * \file callback interface for the compiler
+ * \author Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+#include "gbe_program.h"
+#include "gen/program.h"
+#include "sim/program.h"
+#include "sys/platform.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;
+
+/* Use pre-main to setup the call backs */
+struct CallBackInitializer
+{
+ CallBackInitializer(void) {
+ const char *run_it = getenv("OCL_SIMULATOR");
+ if (run_it != NULL && !strcmp(run_it, "2"))
+ SimSetupCallBacks();
+ else
+ GenSetupCallBacks();
+ }
+};
+
+static CallBackInitializer cbInitializer;
+
--- /dev/null
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+/**
+ * \file program.h
+ * \author Benjamin Segovia <benjamin.segovia@intel.com>
+ *
+ * C-like interface for the gen kernels and programs (either real Gen ISA or Gen
+ * simulator)
+ */
+
+#ifndef __GBE_PROGRAM_H__
+#define __GBE_PROGRAM_H__
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*! Opaque structure that interfaces a GBE program */
+typedef struct GBEProgram GBEProgram;
+
+/*! Opaque structure that interfaces a GBE kernel (ie one OCL function) */
+typedef struct GBEKernel GBEKernel;
+
+/*! 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
+};
+
+/*! Create a new program from the given source code (zero terminated string) */
+typedef GBEProgram *(GBEProgramNewFromSourceCB)(const char *source);
+extern GBEProgramNewFromSourceCB *GBEProgramNewFromSource;
+
+/*! Create a new program from the given blob */
+typedef GBEProgram *(GBEProgramNewFromBinaryCB)(const char *binary, size_t size);
+extern GBEProgramNewFromBinaryCB *GBEProgramNewFromBinary;
+
+/*! 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;
+
+/*! Destroy and deallocate the given program */
+typedef void (GBEProgramDeleteCB)(GBEProgram*);
+extern GBEProgramDeleteCB *GBEProgramDelete;
+
+/*! Get the number of functions in the program */
+typedef uint32_t (GBEProgramGetKernelNumCB)(const GBEProgram*);
+extern GBEProgramGetKernelNumCB *GBEProgramGetKernelNum;
+
+/*! Get the kernel from its name */
+typedef const GBEKernel *(GBEProgramGetKernelByNameCB)(const GBEProgram*, const char *name);
+extern GBEProgramGetKernelByNameCB *GBEProgramGetKernelByName;
+
+/*! Get the kernel from its ID */
+typedef const GBEKernel *(GBEProgramGetKernelCB)(const GBEProgram*, uint32_t ID);
+extern GBEProgramGetKernelCB *GBEProgramGetKernel;
+
+/*! Get the GBE kernel name */
+typedef const char *(GBEKernelGetNameCB)(const GBEKernel*);
+extern GBEKernelGetNameCB *GBEKernelGetName;
+
+/*! Get the GBE kernel source code */
+typedef const char *(GBEKernelGetCodeCB)(const GBEKernel*);
+extern GBEKernelGetCodeCB *GBEKernelGetCode;
+
+/*! Get the size of the source code */
+typedef const size_t (GBEKernelGetCodeSizeCB)(const GBEKernel*);
+extern GBEKernelGetCodeSizeCB *GBEKernelGetCodeSize;
+
+/*! Get the total number of arguments */
+typedef uint32_t (GBEKernelGetArgNumCB)(const GBEKernel*);
+extern GBEKernelGetArgNumCB *GBEKernelGetArgNum;
+
+/*! Get the size of the given argument */
+typedef uint32_t (GBEKernelGetArgSizeCB)(const GBEKernel*, uint32_t argID);
+extern GBEKernelGetArgSizeCB *GBEKernelGetArgSize;
+
+/*! Get the type of the given argument */
+typedef enum GBEArgType (GBEKernelGetArgTypeCB)(const GBEKernel*, uint32_t argID);
+extern GBEKernelGetArgTypeCB *GBEKernelGetArgType;
+
+/*! Get the simd width for the kernel */
+typedef uint32_t (GBEKernelGetSIMDWidthCB)(const GBEKernel*);
+extern GBEKernelGetSIMDWidthCB *GBEKernelGetSIMDWidth;
+
+/*! 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;
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __GBE_PROGRAM_H__ */
+
* \author Benjamin Segovia <benjamin.segovia@intel.com>
*/
+#include "program.h"
#include "gen/program.h"
#include "gen/program.hpp"
+#include "gen/program.hpp"
+#include "gen/brw_eu.h"
#include "ir/liveness.hpp"
#include "ir/value.hpp"
#include "ir/unit.hpp"
#include "llvm/llvm_to_gen.hpp"
-#include "gen/brw_eu.h"
#include <cstring>
namespace gbe {
/////////////////////////////////////////////////////////////////////////////
// C interface for the Gen Programs
/////////////////////////////////////////////////////////////////////////////
-GBE_EXPORT_SYMBOL
-GenProgram *GenProgramNewFromSource(const char *source) {
+static
+GBEProgram *GenProgramNewFromSource(const char *source) {
NOT_IMPLEMENTED;
return NULL;
}
-GBE_EXPORT_SYMBOL
-GenProgram *GenProgramNewFromBinary(const char *binary, size_t size) {
+static
+GBEProgram *GenProgramNewFromBinary(const char *binary, size_t size) {
NOT_IMPLEMENTED;
return NULL;
}
-GBE_EXPORT_SYMBOL
-GenProgram *GenProgramNewFromLLVM(const char *fileName,
+static
+GBEProgram *GenProgramNewFromLLVM(const char *fileName,
size_t stringSize,
char *err,
size_t *errSize)
}
// Everything run fine
- return (GenProgram *) program;
+ return (GBEProgram *) program;
}
-GBE_EXPORT_SYMBOL
-void GenProgramDelete(GenProgram *genProgram) {
+static
+void GenProgramDelete(GBEProgram *genProgram) {
gbe::gen::Program *program = (gbe::gen::Program*)(genProgram);
GBE_SAFE_DELETE(program);
}
/////////////////////////////////////////////////////////////////////////////
// C interface for the Gen Kernels
/////////////////////////////////////////////////////////////////////////////
-GBE_EXPORT_SYMBOL
-uint32_t GenProgramGetKernelNum(const GenProgram *genProgram) {
+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();
}
-GBE_EXPORT_SYMBOL
-const GenKernel *GenProgramGetKernelByName(const GenProgram *genProgram, const char *name) {
+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 (GenKernel*) program->getKernel(std::string(name));
+ return (GBEKernel*) program->getKernel(std::string(name));
}
-GBE_EXPORT_SYMBOL
-const GenKernel *GenProgramGetKernel(const GenProgram *genProgram, uint32_t ID) {
+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 (GenKernel*) program->getKernel(ID);
+ return (GBEKernel*) program->getKernel(ID);
}
-GBE_EXPORT_SYMBOL
-const char *GenKernelGetName(const GenKernel *genKernel) {
+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();
}
-GBE_EXPORT_SYMBOL
-const char *GenKernelGetCode(const GenKernel *genKernel) {
+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();
}
-GBE_EXPORT_SYMBOL
-const size_t GenKernelGetCodeSize(const GenKernel *genKernel) {
+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();
}
-GBE_EXPORT_SYMBOL
-uint32_t GenKernelGetArgNum(const GenKernel *genKernel) {
+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();
}
-GBE_EXPORT_SYMBOL
-uint32_t GenKernelGetArgSize(const GenKernel *genKernel, uint32_t argID) {
+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);
}
-GBE_EXPORT_SYMBOL
-GenArgType GenKernelGetArgType(const GenKernel *genKernel, uint32_t 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);
}
-GBE_EXPORT_SYMBOL
-uint32_t GenKernelGetSIMDWidth(const GenKernel *kernel) {
+static uint32_t GenKernelGetSIMDWidth(const GBEKernel *kernel) {
return 16u;
}
-GBE_EXPORT_SYMBOL
-uint32_t GenKernelGetRequiredWorkGroupSize(const GenKernel *kernel, uint32_t dim) {
+static uint32_t GenKernelGetRequiredWorkGroupSize(const GBEKernel *kernel, uint32_t dim) {
return 0u;
}
+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;
+}
+
#include <stdint.h>
#include <stdlib.h>
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-/*! Opaque structure that interfaces a Gen program */
-typedef struct GenProgram GenProgram;
-
-/*! Opaque structure that interfaces a Gen kernel (ie one OCL function) */
-typedef struct GenKernel GenKernel;
-
-/*! Argument type for each function call */
-enum GenArgType {
- 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
-};
-
-/*! Create a new program from the given source code (zero terminated string) */
-GenProgram *GenProgramNewFromSource(const char *source);
-
-/*! Create a new program from the given blob */
-GenProgram *GenProgramNewFromBinary(const char *binary, size_t size);
-
-/*! Create a new program from the given LLVM file */
-GenProgram *GenProgramNewFromLLVM(const char *fileName,
- size_t stringSize,
- char *err,
- size_t *errSize);
-
-/*! Destroy and deallocate the given program */
-void GenProgramDelete(GenProgram *program);
-
-/*! Get the number of functions in the program */
-uint32_t GenProgramGetKernelNum(const GenProgram *program);
-
-/*! Get the kernel from its name */
-const GenKernel *GenProgramGetKernelByName(const GenProgram *program, const char *name);
-
-/*! Get the kernel from its ID */
-const GenKernel *GenProgramGetKernel(const GenProgram *program, uint32_t ID);
-
-/*! Get the Gen kernel name */
-const char *GenKernelGetName(const GenKernel *kernel);
-
-/*! Get the Gen kernel source code */
-const char *GenKernelGetCode(const GenKernel *kernel);
-
-/*! Get the size of the source code */
-const size_t GenKernelGetCodeSize(const GenKernel *kernel);
-
-/*! Get the total number of arguments */
-uint32_t GenKernelGetArgNum(const GenKernel *kernel);
-
-/*! Get the size of the given argument */
-uint32_t GenKernelGetArgSize(const GenKernel *kernel, uint32_t argID);
-
-/*! Get the type of the given argument */
-enum GenArgType GenKernelGetArgType(const GenKernel *kernel, uint32_t argID);
-
-/*! Get the simd width for the kernel */
-uint32_t GenKernelGetSIMDWidth(const GenKernel *kernel);
-
-/*! Indicates if a work group size is required. Return the required width or 0
- * if none
- */
-uint32_t GenKernelGetRequiredWorkGroupSize(const GenKernel *kernel, uint32_t dim);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+/*! This will make the compiler output Gen ISA code */
+extern void GenSetupCallBacks(void);
#endif /* __GBE_GEN_PROGRAM_H__ */
#ifndef __GBE_GEN_PROGRAM_HPP__
#define __GBE_GEN_PROGRAM_HPP__
+#include "gbe_program.h"
#include "gen/brw_structs.h"
#include "sys/hash_map.hpp"
#include <string>
namespace gen {
struct KernelArgument {
- GenArgType type; //!< Pointer, structure, regular value?
+ GBEArgType type; //!< Pointer, structure, regular value?
size_t size; //!< Size of each argument
};
return args[argID].size;
}
/*! Return the type of the given argument */
- INLINE GenArgType getArgType(uint32_t argID) const {
+ INLINE GBEArgType getArgType(uint32_t argID) const {
if (argID >= argNum)
return GEN_ARG_INVALID;
else
--- /dev/null
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+/**
+ * \file program.cpp
+ * \author Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+#include "gbe_program.h"
+#include "sim/program.h"
+
+namespace gbe {
+namespace sim {
+
+
+} /* namespace sim */
+} /* namespace gen */
+
+ void SimSetupCallBacks(void)
+ {
+#if 0
+ GBEProgramNewFromSource = SimProgramNewFromSource;
+ GBEProgramNewFromBinary = SimProgramNewFromBinary;
+ GBEProgramNewFromLLVM = SimProgramNewFromLLVM;
+ GBEProgramDelete = SimProgramDelete;
+ GBEProgramGetKernelNum = SimProgramGetKernelNum;
+ GBEProgramGetKernelByName = SimProgramGetKernelByName;
+ GBEProgramGetKernel = SimProgramGetKernel;
+ GBEKernelGetName = SimKernelGetName;
+ GBEKernelGetCode = SimKernelGetCode;
+ GBEKernelGetCodeSize = SimKernelGetCodeSize;
+ GBEKernelGetArgNum = SimKernelGetArgNum;
+ GBEKernelGetArgSize = SimKernelGetArgSize;
+ GBEKernelGetArgType = SimKernelGetArgType;
+ GBEKernelGetSIMDWidth = SimKernelGetSIMDWidth;
+ GBEKernelGetRequiredWorkGroupSize = SimKernelGetRequiredWorkGroupSize;
+#endif
+ }
+
--- /dev/null
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+/**
+ * \file program.h
+ * \author Benjamin Segovia <benjamin.segovia@intel.com>
+ *
+ * C-like interface for the gen kernels and programs
+ */
+
+#ifndef __GBE_SIM_PROGRAM_H__
+#define __GBE_SIM_PROGRAM_H__
+
+#include <stdint.h>
+#include <stdlib.h>
+
+/*! This will make the compiler output Gen ISA code */
+extern void SimSetupCallBacks(void);
+
+#endif /* __GBE_SIM_PROGRAM_H__ */
+