summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/CMakeLists.txt2
-rw-r--r--backend/Makefile.defs2
-rw-r--r--backend/src/backend/context.cpp5
-rw-r--r--backend/src/backend/context.hpp4
-rw-r--r--backend/src/backend/gen_context.cpp6
-rw-r--r--backend/src/backend/gen_context.hpp2
-rw-r--r--backend/src/backend/gen_program.cpp8
-rw-r--r--backend/src/backend/gen_reg_allocation.cpp39
-rw-r--r--backend/src/backend/gen_reg_allocation.hpp2
-rw-r--r--backend/src/backend/sim_context.cpp3
-rw-r--r--backend/src/backend/sim_context.hpp2
-rw-r--r--utests/runtime_flat_address_space.cpp8
12 files changed, 45 insertions, 38 deletions
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt
index 74d8cf53..c36f9701 100644
--- a/backend/CMakeLists.txt
+++ b/backend/CMakeLists.txt
@@ -37,7 +37,7 @@ set (CMAKE_C_CXX_FLAGS "-fvisibility=hidden")
if (COMPILER STREQUAL "GCC")
set (CMAKE_C_CXX_FLAGS "${CMAKE_C_CXX_FLAGS} -funroll-loops -Wstrict-aliasing=2 -fstrict-aliasing -msse2 -msse3 -mssse3 -msse4.1 -ffast-math -fPIC -Wall")
- set (CMAKE_CXX_FLAGS "${CMAKE_C_CXX_FLAGS} -Wno-invalid-offsetof -fno-rtti -std=c++0x")
+ set (CMAKE_CXX_FLAGS "${CMAKE_C_CXX_FLAGS} -fno-exceptions -Wno-invalid-offsetof -fno-rtti -std=c++0x")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GBE_DEBUG_MEMORY_FLAG}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GBE_COMPILE_UTESTS_FLAG}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-E")
diff --git a/backend/Makefile.defs b/backend/Makefile.defs
index 8af8f952..8f936a84 100644
--- a/backend/Makefile.defs
+++ b/backend/Makefile.defs
@@ -1,4 +1,4 @@
-LOCAL_CFLAGS=-funroll-loops -Wstrict-aliasing=2 -fstrict-aliasing \
+LOCAL_CFLAGS=-funroll-loops -Wstrict-aliasing=2 -fstrict-aliasing -fno-exceptions\
-msse2 -msse3 -mssse3 -msse4.1 -ffast-math -fPIC -Wall \
-DNDEBUG -DGBE_DEBUG=0 -I$(TOP)/src
diff --git a/backend/src/backend/context.cpp b/backend/src/backend/context.cpp
index 6d787735..660ff19f 100644
--- a/backend/src/backend/context.cpp
+++ b/backend/src/backend/context.cpp
@@ -268,7 +268,10 @@ namespace gbe
this->buildUsedLabels();
this->buildJIPs();
this->buildStack();
- this->emitCode();
+ if (this->emitCode() == false) {
+ GBE_DELETE(this->kernel);
+ this->kernel = NULL;
+ }
return this->kernel;
}
diff --git a/backend/src/backend/context.hpp b/backend/src/backend/context.hpp
index bbf0dc93..296a6af8 100644
--- a/backend/src/backend/context.hpp
+++ b/backend/src/backend/context.hpp
@@ -87,8 +87,8 @@ namespace gbe
/*! Deallocate previously allocated memory */
void deallocate(int16_t offset);
protected:
- /*! Build the instruction stream (to be implemented) */
- virtual void emitCode(void) = 0;
+ /*! Build the instruction stream. Return false if failed */
+ virtual bool emitCode(void) = 0;
/*! Allocate a new empty kernel (to be implemented) */
virtual Kernel *allocateKernel(void) = 0;
/*! Look if a stack is needed and allocate it */
diff --git a/backend/src/backend/gen_context.cpp b/backend/src/backend/gen_context.cpp
index cf7f35cc..366ea0da 100644
--- a/backend/src/backend/gen_context.cpp
+++ b/backend/src/backend/gen_context.cpp
@@ -377,10 +377,11 @@ namespace gbe
}
BVAR(OCL_OUTPUT_ASM, false);
- void GenContext::emitCode(void) {
+ bool GenContext::emitCode(void) {
GenKernel *genKernel = static_cast<GenKernel*>(this->kernel);
sel->select();
- ra->allocate(*this->sel);
+ if (UNLIKELY(ra->allocate(*this->sel) == false))
+ return false;
this->emitStackPointer();
this->emitInstructionStream();
this->patchBranches();
@@ -390,6 +391,7 @@ namespace gbe
if (OCL_OUTPUT_ASM)
for (uint32_t insnID = 0; insnID < genKernel->insnNum; ++insnID)
gen_disasm(stdout, &p->store[insnID]);
+ return true;
}
Kernel *GenContext::allocateKernel(void) {
diff --git a/backend/src/backend/gen_context.hpp b/backend/src/backend/gen_context.hpp
index 627cd3d7..73da0a56 100644
--- a/backend/src/backend/gen_context.hpp
+++ b/backend/src/backend/gen_context.hpp
@@ -54,7 +54,7 @@ namespace gbe
/*! Release everything needed */
~GenContext(void);
/*! Implements base class */
- virtual void emitCode(void);
+ virtual bool emitCode(void);
/*! Function we emit code for */
INLINE const ir::Function &getFunction(void) const { return fn; }
/*! Simd width chosen for the current function */
diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
index 835fbfb6..e59b9e8d 100644
--- a/backend/src/backend/gen_program.cpp
+++ b/backend/src/backend/gen_program.cpp
@@ -48,17 +48,15 @@ namespace gbe {
Kernel *GenProgram::compileKernel(const ir::Unit &unit, const std::string &name) {
Context *ctx = GBE_NEW(GenContext, unit, name);
- Kernel *kernel = NULL;
+ Kernel *kernel = ctx->compileKernel();
// register allocation may fail. We may need to recompile in that case
- try {
- kernel = ctx->compileKernel();
- } catch (NotEnoughRegisterException e) {
- GBE_SAFE_DELETE(ctx->getKernel());
+ if (kernel == NULL) {
GBE_SAFE_DELETE(ctx);
unit.getFunction(name)->setSimdWidth(8);
ctx = GBE_NEW(GenContext, unit, name);
kernel = ctx->compileKernel();
+ GBE_ASSERT(kernel != NULL); // XXX spill must be implemented
}
GBE_DELETE(ctx);
return kernel;
diff --git a/backend/src/backend/gen_reg_allocation.cpp b/backend/src/backend/gen_reg_allocation.cpp
index e1a58dfc..56664d6c 100644
--- a/backend/src/backend/gen_reg_allocation.cpp
+++ b/backend/src/backend/gen_reg_allocation.cpp
@@ -50,8 +50,8 @@ namespace gbe
Opaque(GenContext &ctx);
/*! Release all taken resources */
~Opaque(void);
- /*! Perform the register allocation */
- void allocate(Selection &selection);
+ /*! Perform the register allocation. Return true if success */
+ bool allocate(Selection &selection);
/*! Return the Gen register from the selection register */
GenRegister genReg(const GenRegister &reg);
private:
@@ -62,14 +62,14 @@ namespace gbe
/*! Allocate the virtual boolean (== flags) registers */
void allocateFlags(Selection &selection);
/*! Allocate the GRF registers */
- void allocateGRFs(Selection &selection);
+ bool allocateGRFs(Selection &selection);
/*! Create a Gen register from a register set in the payload */
void allocatePayloadReg(gbe_curbe_type, ir::Register, uint32_t subValue = 0, uint32_t subOffset = 0);
/*! Create the intervals for each register */
/*! Allocate the vectors detected in the instruction selection pass */
void allocateVector(Selection &selection);
- /*! Create the given interval */
- void createGenReg(const GenRegInterval &interval);
+ /*! Allocate the given interval. Return true if success */
+ bool createGenReg(const GenRegInterval &interval);
/*! Indicate if the registers are already allocated in vectors */
bool isAllocated(const SelectionVector *vector) const;
/*! Reallocate registers if needed to make the registers in the vector
@@ -133,11 +133,12 @@ namespace gbe
}
}
- void GenRegAllocator::Opaque::createGenReg(const GenRegInterval &interval) {
+ bool GenRegAllocator::Opaque::createGenReg(const GenRegInterval &interval) {
using namespace ir;
const ir::Register reg = interval.reg;
const uint32_t simdWidth = ctx.getSimdWidth();
- if (RA.contains(reg) == true) return; // already allocated
+ if (RA.contains(reg) == true)
+ return true; // already allocated
GBE_ASSERT(ctx.isScalarReg(reg) == false);
const bool isScalar = ctx.sel->isScalarOrBool(reg);
const RegisterData regData = ctx.sel->getRegisterData(reg);
@@ -146,14 +147,12 @@ namespace gbe
const uint32_t regSize = simdWidth*typeSize;
uint32_t grfOffset;
while ((grfOffset = ctx.allocate(regSize, regSize)) == 0) {
- //IF_DEBUG(const bool success =) this->expireGRF(interval);
- //GBE_ASSERTM(success, "Register allocation failed");
const bool success = this->expireGRF(interval);
- if (UNLIKELY(success == false))
- throw NotEnoughRegisterException();
+ if (UNLIKELY(success == false)) return false;
}
GBE_ASSERTM(grfOffset != 0, "Unable to register allocate");
RA.insert(std::make_pair(reg, grfOffset));
+ return true;
}
bool GenRegAllocator::Opaque::isAllocated(const SelectionVector *vector) const {
@@ -442,7 +441,7 @@ namespace gbe
}
}
- void GenRegAllocator::Opaque::allocateGRFs(Selection &selection) {
+ bool GenRegAllocator::Opaque::allocateGRFs(Selection &selection) {
// Perform the linear scan allocator
const uint32_t regNum = ctx.sel->getRegNum();
@@ -465,8 +464,7 @@ namespace gbe
uint32_t grfOffset;
while ((grfOffset = ctx.allocate(size, alignment)) == 0) {
const bool success = this->expireGRF(interval);
- if (UNLIKELY(success == false))
- throw NotEnoughRegisterException();
+ if (success == false) return false;
}
for (uint32_t regID = 0; regID < vector->regNum; ++regID, grfOffset += alignment) {
const ir::Register reg = vector->reg[regID].reg();
@@ -475,12 +473,13 @@ namespace gbe
}
}
// Case 2: This is a regular scalar register, allocate it alone
- else
- this->createGenReg(interval);
+ else if (this->createGenReg(interval) == false)
+ return false;
}
+ return true;
}
- INLINE void GenRegAllocator::Opaque::allocate(Selection &selection) {
+ INLINE bool GenRegAllocator::Opaque::allocate(Selection &selection) {
using namespace ir;
const Kernel *kernel = ctx.getKernel();
const Function &fn = ctx.getFunction();
@@ -649,7 +648,7 @@ namespace gbe
// Allocate all the GRFs now (regular register and boolean that are not in
// flag registers)
- this->allocateGRFs(selection);
+ return this->allocateGRFs(selection);
}
INLINE GenRegister setGenReg(const GenRegister &src, uint32_t grfOffset) {
@@ -687,8 +686,8 @@ namespace gbe
GBE_DELETE(this->opaque);
}
- void GenRegAllocator::allocate(Selection &selection) {
- this->opaque->allocate(selection);
+ bool GenRegAllocator::allocate(Selection &selection) {
+ return this->opaque->allocate(selection);
}
GenRegister GenRegAllocator::genReg(const GenRegister &reg) {
diff --git a/backend/src/backend/gen_reg_allocation.hpp b/backend/src/backend/gen_reg_allocation.hpp
index 1e634aac..ab4af2ad 100644
--- a/backend/src/backend/gen_reg_allocation.hpp
+++ b/backend/src/backend/gen_reg_allocation.hpp
@@ -45,7 +45,7 @@ namespace gbe
/*! Release all taken resources */
~GenRegAllocator(void);
/*! Perform the register allocation */
- void allocate(Selection &selection);
+ bool allocate(Selection &selection);
/*! Virtual to physical translation */
GenRegister genReg(const GenRegister &reg);
private:
diff --git a/backend/src/backend/sim_context.cpp b/backend/src/backend/sim_context.cpp
index 1bcb206b..f61cf916 100644
--- a/backend/src/backend/sim_context.cpp
+++ b/backend/src/backend/sim_context.cpp
@@ -390,7 +390,7 @@ namespace gbe
SVAR(OCL_ICC_SIM_COMPILER_OPTIONS, "-Wall -ldl -fabi-version=2 -fPIC -shared -O3 -g");
BVAR(OCL_USE_ICC, false);
- void SimContext::emitCode(void) {
+ bool SimContext::emitCode(void) {
SimKernel *simKernel = static_cast<SimKernel*>(this->kernel);
char srcStr[L_tmpnam+1], libStr[L_tmpnam+1];
const std::string srcName = std::string(tmpnam_r(srcStr)) + ".cpp"; /* unsafe! */
@@ -440,6 +440,7 @@ namespace gbe
simKernel->fn = (SimKernelCallBack*) dlsym(simKernel->handle, name.c_str());
if (UNLIKELY(simKernel->fn == NULL))
FATAL("Failed to get the symbol from the compiled shared object");
+ return true;
}
} /* namespace gbe */
diff --git a/backend/src/backend/sim_context.hpp b/backend/src/backend/sim_context.hpp
index e660866c..c6dfa17b 100644
--- a/backend/src/backend/sim_context.hpp
+++ b/backend/src/backend/sim_context.hpp
@@ -47,7 +47,7 @@ namespace gbe
/*! Release everything needed */
~SimContext(void);
/*! Implements base class */
- virtual void emitCode(void);
+ virtual bool emitCode(void);
/*! Emit all the register declarations */
void emitRegisters(void);
/*! Load the curbe data into the registers */
diff --git a/utests/runtime_flat_address_space.cpp b/utests/runtime_flat_address_space.cpp
index d2f4aefb..0357cbd0 100644
--- a/utests/runtime_flat_address_space.cpp
+++ b/utests/runtime_flat_address_space.cpp
@@ -23,7 +23,7 @@ int
main(int argc, char *argv[])
{
cl_mem dst[24];
- int *dst_buffer;
+ int *dst_buffer = NULL;
const size_t n = 32 * 1024 * 1024;
const size_t global_work_size = n;
const size_t local_work_size = 16;
@@ -56,7 +56,11 @@ main(int argc, char *argv[])
dst_buffer = (int *) clIntelMapBuffer(dst[j], &status);
if (status != CL_SUCCESS)
goto error;
- for (uint32_t i = 0; i < n; ++i) assert(dst_buffer[i] == int(i));
+ for (uint32_t i = 0; i < n; ++i)
+ if (dst_buffer[i] != int(i)) {
+ fprintf(stderr, "run-time flat address space failed\n");
+ exit(-1);
+ }
OCL_CALL (clIntelUnmapBuffer, dst[j]);
}