diff options
| author | Benjamin Segovia <bsegovia@bsegovia-i70.sc.intel.com> | 2012-09-19 20:40:10 +0000 |
|---|---|---|
| committer | Benjamin Segovia <bsegovia@bsegovia-i70.sc.intel.com> | 2012-09-19 20:40:10 +0000 |
| commit | d8ffb5dcd384a9f68bb6d0900b6d63d6444342e3 (patch) | |
| tree | d4ebe30ab3fdb3c46f265d6bf4c3199e9c47e39f | |
| parent | 5c34e90c2b6e92c4406a8997b570ee2c7240c8ff (diff) | |
Removed unused files
Added extra functionalities to debug special allocator with valgrind
| -rw-r--r-- | backend/src/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | backend/src/backend/context.cpp | 2 | ||||
| -rw-r--r-- | backend/src/backend/gen_context.cpp | 2 | ||||
| -rw-r--r-- | backend/src/backend/gen_insn_selection.cpp | 22 | ||||
| -rw-r--r-- | backend/src/backend/gen_reg_allocation.cpp | 20 | ||||
| -rw-r--r-- | backend/src/ir/function.cpp | 7 | ||||
| -rw-r--r-- | backend/src/ir/register.cpp | 3 | ||||
| -rw-r--r-- | backend/src/math/math.hpp | 113 | ||||
| -rw-r--r-- | backend/src/ocl_stdlib.h | 7 | ||||
| -rw-r--r-- | backend/src/ocl_stdlib_str.cpp | 23 | ||||
| -rw-r--r-- | backend/src/sys/alloc.cpp | 62 | ||||
| -rw-r--r-- | backend/src/sys/alloc.hpp | 25 | ||||
| -rw-r--r-- | backend/src/sys/barrier.hpp | 67 | ||||
| -rw-r--r-- | backend/src/sys/condition.cpp | 144 | ||||
| -rw-r--r-- | backend/src/sys/condition.hpp | 45 | ||||
| -rw-r--r-- | backend/src/sys/constants.hpp | 150 | ||||
| -rw-r--r-- | backend/src/sys/platform.hpp | 5 | ||||
| -rw-r--r-- | backend/src/sys/string.cpp | 113 | ||||
| -rw-r--r-- | backend/src/sys/string.hpp | 58 | ||||
| -rw-r--r-- | backend/src/sys/sysinfo.cpp | 153 | ||||
| -rw-r--r-- | backend/src/sys/sysinfo.hpp | 42 |
21 files changed, 91 insertions, 978 deletions
diff --git a/backend/src/CMakeLists.txt b/backend/src/CMakeLists.txt index 950ea213..1bcac381 100644 --- a/backend/src/CMakeLists.txt +++ b/backend/src/CMakeLists.txt @@ -40,16 +40,10 @@ else (GBE_USE_BLOB) sys/exception.hpp sys/assert.cpp sys/assert.hpp - sys/string.cpp - sys/string.hpp sys/alloc.cpp sys/alloc.hpp - sys/sysinfo.cpp - sys/sysinfo.hpp sys/mutex.cpp sys/mutex.hpp - sys/condition.cpp - sys/condition.hpp sys/platform.cpp sys/platform.hpp sys/cvar.cpp diff --git a/backend/src/backend/context.cpp b/backend/src/backend/context.cpp index 11eed2c6..ebf4e6e4 100644 --- a/backend/src/backend/context.cpp +++ b/backend/src/backend/context.cpp @@ -296,7 +296,7 @@ namespace gbe const uint32_t offset = partitioner->allocate(size, alignment); GBE_ASSERT(offset >= GEN_REG_SIZE); kernel->patches.push_back(PatchInfo(value, subValue, offset - GEN_REG_SIZE)); - kernel->curbeSize = max(kernel->curbeSize, offset + size - GEN_REG_SIZE); + kernel->curbeSize = std::max(kernel->curbeSize, offset + size - GEN_REG_SIZE); } void Context::buildPatchList(void) { diff --git a/backend/src/backend/gen_context.cpp b/backend/src/backend/gen_context.cpp index bd936d41..59dd1545 100644 --- a/backend/src/backend/gen_context.cpp +++ b/backend/src/backend/gen_context.cpp @@ -1,5 +1,5 @@ /* - * Copyright © 2012 Intel Corporation + * Copyright © 2012 Intel Corporatin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/backend/src/backend/gen_insn_selection.cpp b/backend/src/backend/gen_insn_selection.cpp index 31e09453..71ae1748 100644 --- a/backend/src/backend/gen_insn_selection.cpp +++ b/backend/src/backend/gen_insn_selection.cpp @@ -462,8 +462,8 @@ namespace gbe } SelectionInstruction *Selection::Opaque::appendInsn(SelectionOpcode opcode, - uint32_t dstNum, - uint32_t srcNum) + uint32_t dstNum, + uint32_t srcNum) { GBE_ASSERT(this->block != NULL); SelectionInstruction *insn = this->create(opcode, dstNum, srcNum); @@ -603,9 +603,9 @@ namespace gbe void Selection::Opaque::WAIT(void) { this->appendInsn(SEL_OP_WAIT, 0, 0); } void Selection::Opaque::UNTYPED_READ(Reg addr, - const GenRegister *dst, - uint32_t elemNum, - uint32_t bti) + const GenRegister *dst, + uint32_t elemNum, + uint32_t bti) { SelectionInstruction *insn = this->appendInsn(SEL_OP_UNTYPED_READ, elemNum, 1); SelectionVector *srcVector = this->appendVector(); @@ -630,9 +630,9 @@ namespace gbe } void Selection::Opaque::UNTYPED_WRITE(Reg addr, - const GenRegister *src, - uint32_t elemNum, - uint32_t bti) + const GenRegister *src, + uint32_t elemNum, + uint32_t bti) { SelectionInstruction *insn = this->appendInsn(SEL_OP_UNTYPED_WRITE, 0, elemNum+1); SelectionVector *vector = this->appendVector(); @@ -717,9 +717,9 @@ namespace gbe } void Selection::Opaque::REGION(Reg dst0, Reg dst1, const GenRegister *src, - uint32_t offset, uint32_t vstride, - uint32_t width, uint32_t hstride, - uint32_t srcNum) + uint32_t offset, uint32_t vstride, + uint32_t width, uint32_t hstride, + uint32_t srcNum) { SelectionInstruction *insn = this->appendInsn(SEL_OP_REGION, 2, srcNum); SelectionVector *vector = this->appendVector(); diff --git a/backend/src/backend/gen_reg_allocation.cpp b/backend/src/backend/gen_reg_allocation.cpp index 8a06d3ee..b3d8a87b 100644 --- a/backend/src/backend/gen_reg_allocation.cpp +++ b/backend/src/backend/gen_reg_allocation.cpp @@ -555,8 +555,8 @@ namespace gbe reg == ir::ocl::groupid1 || reg == ir::ocl::groupid2) continue; - this->intervals[reg].minID = min(this->intervals[reg].minID, insnID); - this->intervals[reg].maxID = max(this->intervals[reg].maxID, insnID); + this->intervals[reg].minID = std::min(this->intervals[reg].minID, insnID); + this->intervals[reg].maxID = std::max(this->intervals[reg].maxID, insnID); } for (uint32_t dstID = 0; dstID < dstNum; ++dstID) { const GenRegister &selReg = insn.dst(dstID); @@ -566,8 +566,8 @@ namespace gbe reg == ir::ocl::groupid1 || reg == ir::ocl::groupid2) continue; - this->intervals[reg].minID = min(this->intervals[reg].minID, insnID); - this->intervals[reg].maxID = max(this->intervals[reg].maxID, insnID); + this->intervals[reg].minID = std::min(this->intervals[reg].minID, insnID); + this->intervals[reg].maxID = std::max(this->intervals[reg].maxID, insnID); } // Flag registers can only go to src[0] @@ -583,8 +583,8 @@ namespace gbe // OK, a flag is used as a predicate or a conditional modifier if (insn.state.physicalFlag == 0) { const ir::Register reg = ir::Register(insn.state.flagIndex); - this->intervals[reg].minID = min(this->intervals[reg].minID, insnID); - this->intervals[reg].maxID = max(this->intervals[reg].maxID, insnID); + this->intervals[reg].minID = std::min(this->intervals[reg].minID, insnID); + this->intervals[reg].maxID = std::max(this->intervals[reg].maxID, insnID); } lastID = insnID; insnID++; @@ -595,8 +595,8 @@ namespace gbe const ir::BasicBlock *bb = block.bb; const ir::Liveness::LiveOut &liveOut = ctx.getLiveOut(bb); for (auto reg : liveOut) { - this->intervals[reg].minID = min(this->intervals[reg].minID, lastID); - this->intervals[reg].maxID = max(this->intervals[reg].maxID, lastID); + this->intervals[reg].minID = std::min(this->intervals[reg].minID, lastID); + this->intervals[reg].maxID = std::max(this->intervals[reg].maxID, lastID); } }); @@ -611,8 +611,8 @@ namespace gbe int32_t maxID = this->intervals[first].maxID; for (uint32_t regID = 1; regID < regNum; ++regID) { const ir::Register reg = vector->reg[regID].reg(); - minID = min(minID, this->intervals[reg].minID); - maxID = max(maxID, this->intervals[reg].maxID); + minID = std::min(minID, this->intervals[reg].minID); + maxID = std::max(maxID, this->intervals[reg].maxID); } for (uint32_t regID = 0; regID < regNum; ++regID) { const ir::Register reg = vector->reg[regID].reg(); diff --git a/backend/src/ir/function.cpp b/backend/src/ir/function.cpp index bdb34a9e..3e564ffb 100644 --- a/backend/src/ir/function.cpp +++ b/backend/src/ir/function.cpp @@ -23,7 +23,6 @@ */ #include "ir/function.hpp" #include "ir/unit.hpp" -#include "sys/string.hpp" #include "sys/map.hpp" namespace gbe { @@ -190,7 +189,7 @@ namespace ir { out << ".decl_function " << fn.getName() << std::endl; out << fn.getRegisterFile(); out << "## " << fn.argNum() << " input register" - << plural(fn.argNum()) << " ##" << std::endl; + << (fn.argNum() ? "s" : "") << " ##" << std::endl; for (uint32_t i = 0; i < fn.argNum(); ++i) { const FunctionArgument &input = fn.getArg(i); out << "decl_input."; @@ -207,7 +206,7 @@ namespace ir { out << " %" << input.reg << std::endl; } out << "## " << fn.outputNum() << " output register" - << plural(fn.outputNum()) << " ##" << std::endl; + << (fn.outputNum() ? "s" : "") << " ##" << std::endl; for (uint32_t i = 0; i < fn.outputNum(); ++i) out << "decl_output %" << fn.getOutput(i) << std::endl; out << "## " << fn.pushedNum() << " pushed register" << std::endl; @@ -218,7 +217,7 @@ namespace ir { << pushed.second.offset << "}" << std::endl; } out << "## " << fn.blockNum() << " block" - << plural(fn.blockNum()) << " ##" << std::endl; + << (fn.blockNum() ? "s" : "") << " ##" << std::endl; fn.foreachBlock([&](const BasicBlock &bb) { bb.foreach([&out] (const Instruction &insn) { out << insn << std::endl; diff --git a/backend/src/ir/register.cpp b/backend/src/ir/register.cpp index d2d7b026..12fc941e 100644 --- a/backend/src/ir/register.cpp +++ b/backend/src/ir/register.cpp @@ -22,7 +22,6 @@ * \author Benjamin Segovia <benjamin.segovia@intel.com> */ #include "ir/register.hpp" -#include "sys/string.hpp" namespace gbe { namespace ir { @@ -42,7 +41,7 @@ namespace ir { std::ostream &operator<< (std::ostream &out, const RegisterFile &file) { out << "## " << file.regNum() << " register" - << plural(file.regNum()) << " ##" << std::endl; + << (file.regNum() ? "s" : "") << " ##" << std::endl; for (uint32_t i = 0; i < file.regNum(); ++i) { const RegisterData reg = file.get(Register(i)); out << ".decl." << reg << " %" << i << std::endl; diff --git a/backend/src/math/math.hpp b/backend/src/math/math.hpp deleted file mode 100644 index c13b221c..00000000 --- a/backend/src/math/math.hpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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> - */ - -////////////////////////////////////////////////////////////////////////////////////////// -// Part of this file is taken from the Apache licensed Intel Embree project here: // -// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ // -////////////////////////////////////////////////////////////////////////////////////////// - -#ifndef __GBE_MATH_HPP__ -#define __GBE_MATH_HPP__ - -#include "sys/platform.hpp" - -#include <cmath> -#include <cfloat> - -namespace gbe -{ -#if defined(__WIN32__) - #undef min - #undef max -#if defined(__MSVC__) - INLINE bool finite (float x) {return _finite(x) != 0;} -#endif -#endif - - INLINE float sign (float x) {return x<0?-1.0f:1.0f;} - INLINE float sqr (float x) {return x*x;} - INLINE float rcp (float x) {return 1.0f/x;} - INLINE float rsqrt(float x) {return 1.0f/::sqrtf(x);} - INLINE float abs (float x) {return ::fabsf(x);} - INLINE float acos (float x) {return ::acosf (x);} - INLINE float asin (float x) {return ::asinf (x);} - INLINE float atan (float x) {return ::atanf (x);} - INLINE float cos (float x) {return ::cosf (x);} - INLINE float cosh (float x) {return ::coshf (x);} - INLINE float exp (float x) {return ::expf (x);} - INLINE float log (float x) {return ::logf (x);} - INLINE float log2 (float x) {return ::log(x) / 0.69314718055994530941723212145818f;} - INLINE float log10(float x) {return ::log10f(x);} - INLINE float sin (float x) {return ::sinf (x);} - INLINE float sinh (float x) {return ::sinhf (x);} - INLINE float sqrt (float x) {return ::sqrtf (x);} - INLINE float tan (float x) {return ::tanf (x);} - INLINE float tanh (float x) {return ::tanhf (x);} - INLINE float floor(float x) {return ::floorf (x);} - INLINE float ceil (float x) {return ::ceilf (x);} - INLINE float atan2(float y, float x) {return ::atan2f(y, x);} - INLINE float fmod (float x, float y) {return ::fmodf (x, y);} - INLINE float pow (float x, float y) {return ::powf (x, y);} - - INLINE double abs (double x) {return ::fabs(x);} - INLINE double sign (double x) {return x<0?-1.0:1.0;} - INLINE double acos (double x) {return ::acos (x);} - INLINE double asin (double x) {return ::asin (x);} - INLINE double atan (double x) {return ::atan (x);} - INLINE double cos (double x) {return ::cos (x);} - INLINE double cosh (double x) {return ::cosh (x);} - INLINE double exp (double x) {return ::exp (x);} - INLINE double log (double x) {return ::log (x);} - INLINE double log2 (double x) {return ::log(x) / 0.69314718055994530941723212145818;} - INLINE double log10(double x) {return ::log10(x);} - INLINE double rcp (double x) {return 1.0/x;} - INLINE double rsqrt(double x) {return 1.0/::sqrt(x);} - INLINE double sin (double x) {return ::sin (x);} - INLINE double sinh (double x) {return ::sinh (x);} - INLINE double sqr (double x) {return x*x;} - INLINE double sqrt (double x) {return ::sqrt (x);} - INLINE double tan (double x) {return ::tan (x);} - INLINE double tanh (double x) {return ::tanh (x);} - INLINE double floor(double x) {return ::floor (x);} - INLINE double ceil (double x) {return ::ceil (x);} - INLINE double atan2(double y, double x) {return ::atan2(y, x);} - INLINE double fmod (double x, double y) {return ::fmod (x, y);} - INLINE double pow (double x, double y) {return ::pow (x, y);} - -#define DECL template <typename T> INLINE - - DECL T max (T a, T b) {return a<b? b:a;} - DECL T min (T a, T b) {return a<b? a:b;} - DECL T min (T a, T b, T c) {return min(min(a,b),c);} - DECL T max (T a, T b, T c) {return max(max(a,b),c);} - DECL T max (T a, T b, T c, T d) {return max(max(a,b),max(c,d));} - DECL T min (T a, T b, T c, T d) {return min(min(a,b),min(c,d));} - DECL T min (T a, T b, T c, T d, T e) {return min(min(min(a,b),min(c,d)),e);} - DECL T max (T a, T b, T c, T d, T e) {return max(max(max(a,b),max(c,d)),e);} - DECL T clamp (T x, T lower = T(zero), T upper = T(one)) {return max(lower, min(x,upper));} - DECL T deg2rad (T x) {return x * T(1.74532925199432957692e-2f);} - DECL T rad2deg (T x) {return x * T(5.72957795130823208768e1f);} - DECL T sin2cos (T x) {return sqrt(max(T(zero),T(one)-x*x));} - DECL T cos2sin (T x) {return sin2cos(x);} - -#undef DECL -} - -#endif /* __GBE_MATH_HPP__ */ - diff --git a/backend/src/ocl_stdlib.h b/backend/src/ocl_stdlib.h index a31b2cfa..df6a1926 100644 --- a/backend/src/ocl_stdlib.h +++ b/backend/src/ocl_stdlib.h @@ -17,6 +17,12 @@ * Author: Benjamin Segovia <benjamin.segovia@intel.com> */ +#ifndef __GEN_OCL_STDLIB_H__ +#define __GEN_OCL_STDLIB_H__ + +#define INLINE_OVERLOADABLE __attribute__((overloadable,always_inline)) +#define OVERLOADABLE __attribute__((overloadable)) + ///////////////////////////////////////////////////////////////////////////// // OpenCL basic types ///////////////////////////////////////////////////////////////////////////// @@ -240,4 +246,5 @@ DECL_VOTE(bool) #define NULL ((void*)0) #undef INLINE_OVERLOADABLE +#endif /* __GEN_OCL_STDLIB_H__ */ diff --git a/backend/src/ocl_stdlib_str.cpp b/backend/src/ocl_stdlib_str.cpp index 327504ed..04ba6cf4 100644 --- a/backend/src/ocl_stdlib_str.cpp +++ b/backend/src/ocl_stdlib_str.cpp @@ -1,6 +1,28 @@ #include "string" namespace gbe { std::string ocl_stdlib_str = +"/* \n" +" * Copyright © 2012 Intel Corporation\n" +" *\n" +" * This library is free software; you can redistribute it and/or\n" +" * modify it under the terms of the GNU Lesser General Public\n" +" * License as published by the Free Software Foundation; either\n" +" * version 2 of the License, or (at your option) any later version.\n" +" *\n" +" * This library is distributed in the hope that it will be useful,\n" +" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" +" * Lesser General Public License for more details.\n" +" *\n" +" * You should have received a copy of the GNU Lesser General Public\n" +" * License along with this library. If not, see <http://www.gnu.org/licenses/>.\n" +" *\n" +" * Author: Benjamin Segovia <benjamin.segovia@intel.com>\n" +" */\n" +"\n" +"#ifndef __GEN_OCL_STDLIB_H__\n" +"#define __GEN_OCL_STDLIB_H__\n" +"\n" "#define INLINE_OVERLOADABLE __attribute__((overloadable,always_inline))\n" "#define OVERLOADABLE __attribute__((overloadable))\n" "\n" @@ -227,6 +249,7 @@ std::string ocl_stdlib_str = "\n" "#define NULL ((void*)0)\n" "#undef INLINE_OVERLOADABLE\n" +"#endif /* __GEN_OCL_STDLIB_H__ */\n" "\n" ; } diff --git a/backend/src/sys/alloc.cpp b/backend/src/sys/alloc.cpp index 67368c74..cc2186f1 100644 --- a/backend/src/sys/alloc.cpp +++ b/backend/src/sys/alloc.cpp @@ -29,11 +29,7 @@ #include "sys/mutex.hpp" #if GBE_DEBUG_MEMORY -#ifdef __MSVC__ -#include <unordered_map> -#else #include <tr1/unordered_map> -#endif /* __MSVC__ */ #include <cstring> #endif /* GBE_DEBUG_MEMORY */ @@ -47,6 +43,7 @@ //////////////////////////////////////////////////////////////////////////////// /// Memory debugger //////////////////////////////////////////////////////////////////////////////// + #if GBE_DEBUG_MEMORY namespace gbe { @@ -271,29 +268,6 @@ namespace gbe #else /* GBE_DEBUG_MEMORY */ //////////////////////////////////////////////////////////////////////////////// -/// Windows Platform -//////////////////////////////////////////////////////////////////////////////// - -#if defined(__WIN32__) - -#define WIN32_LEAN_AND_MEAN -#include <windows.h> - -namespace gbe -{ - void* alignedMalloc(size_t size, size_t align) { - void* ptr = _mm_malloc(size,align); - FATAL_IF (!ptr && size, "memory allocation failed"); - MemDebuggerInitializeMem(ptr, size); - return ptr; - } - - void alignedFree(void *ptr) { if (ptr) _mm_free(ptr); } -} /* namespace gbe */ - -#endif /* __WIN32__ */ - -//////////////////////////////////////////////////////////////////////////////// /// Linux Platform //////////////////////////////////////////////////////////////////////////////// @@ -317,34 +291,10 @@ namespace gbe void alignedFree(void *ptr) { if (ptr) std::free(ptr); } } /* namespace gbe */ +#else +#error "Unsupported platform" #endif /* __LINUX__ */ - -//////////////////////////////////////////////////////////////////////////////// -/// MacOS Platform -//////////////////////////////////////////////////////////////////////////////// - -#if defined(__MACOSX__) - -#include <cstdlib> - -namespace gbe -{ - void* alignedMalloc(size_t size, size_t align) { - void* mem = malloc(size+align+sizeof(void*)); - FATAL_IF (!mem && size, "memory allocation failed"); - char* aligned = ((char*)mem) + sizeof(void*); - aligned += align - ((uintptr_t)aligned & (align - 1)); - ((void**)aligned)[-1] = mem; - MemDebuggerInitializeMem(aligned, size); - return aligned; - } - - void alignedFree(void* ptr) { if (ptr) free(((void**)ptr)[-1]); } -} /* namespace gbe */ - -#endif /* __MACOSX__ */ - -#endif /* GBE_DEBUG_MEMORY */ +#endif //////////////////////////////////////////////////////////////////////////////// // Linear allocator @@ -372,6 +322,9 @@ namespace gbe void *LinearAllocator::allocate(size_t size) { +#if GBE_DEBUG_SPECIAL_ALLOCATOR + if (ptr) GBE_ALIGNED_MALLOC(size, sizeof(void*)); +#else // Try to use the current segment. This is the most likely condition here this->curr->offset = ALIGN(this->curr->offset, sizeof(void*)); if (this->curr->offset + size <= this->curr->size) { @@ -399,6 +352,7 @@ namespace gbe char *ptr = (char*) curr->data; this->curr->offset += size; return ptr; +#endif } } /* namespace gbe */ diff --git a/backend/src/sys/alloc.hpp b/backend/src/sys/alloc.hpp index 4629708a..e8e35eb6 100644 --- a/backend/src/sys/alloc.hpp +++ b/backend/src/sys/alloc.hpp @@ -26,7 +26,7 @@ #include "sys/platform.hpp" #include "sys/assert.hpp" -#include "math/math.hpp" +#include <algorithm> namespace gbe { @@ -153,6 +153,11 @@ namespace gbe INLINE bool operator!=(Allocator const& a) { return !operator==(a); } }; +// Deactivate fast allocators +#ifndef GBE_DEBUG_SPECIAL_ALLOCATOR +#define GBE_DEBUG_SPECIAL_ALLOCATOR 0 +#endif + /*! A growing pool never gives memory to the system but chain free elements * together such as deallocation can be quickly done */ @@ -165,6 +170,9 @@ namespace gbe free(NULL), freeList(NULL) {} ~GrowingPool(void) { GBE_ASSERT(curr); GBE_DELETE(curr); } void *allocate(void) { +#if GBE_DEBUG_SPECIAL_ALLOCATOR + return GBE_ALIGNED_MALLOC(sizeof(T), AlignOf<T>::value); +#else // Pick up an element from the free list if (this->freeList != NULL) { void *data = (void*) freeList; @@ -190,13 +198,19 @@ namespace gbe } void *data = (T*) curr->data + curr->allocated++; return data; +#endif /* GBE_DEBUG_SPECIAL_ALLOCATOR */ } void deallocate(void *t) { if (t == NULL) return; +#if GBE_DEBUG_SPECIAL_ALLOCATOR + GBE_ALIGNED_FREE(t); +#else *(void**) t = this->freeList; this->freeList = t; +#endif } void rewind(void) { +#if GBE_DEBUG_SPECIAL_ALLOCATOR == 0 // All free elements return to their blocks this->freeList = NULL; // Reverse the chain list and mark all blocks as empty @@ -211,6 +225,7 @@ namespace gbe GBE_ASSERT(this->free); this->curr = this->free; this->free = this->curr->next; +#endif /* GBE_DEBUG_SPECIAL_ALLOCATOR */ } private: /*! Chunk of elements to allocate */ @@ -218,7 +233,7 @@ namespace gbe { friend class GrowingPool; GrowingPoolElem(size_t elemNum) { - const size_t sz = max(sizeof(T), sizeof(void*)); + const size_t sz = std::max(sizeof(T), sizeof(void*)); this->data = (T*) GBE_ALIGNED_MALLOC(elemNum * sz, AlignOf<T>::value); this->next = NULL; this->maxElemNum = elemNum; @@ -263,7 +278,11 @@ namespace gbe /*! Allocate size bytes */ void *allocate(size_t size); /*! Nothing here */ - INLINE void deallocate(void *ptr) {} + INLINE void deallocate(void *ptr) { +#if GBE_DEBUG_SPECIAL_ALLOCATOR + if (ptr) GBE_ALIGNED_FREE(ptr); +#endif /* GBE_DEBUG_SPECIAL_ALLOCATOR */ + } private: /*! Helds an allocated segment of memory */ struct Segment { diff --git a/backend/src/sys/barrier.hpp b/backend/src/sys/barrier.hpp deleted file mode 100644 index 2721773a..00000000 --- a/backend/src/sys/barrier.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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> - */ - -////////////////////////////////////////////////////////////////////////////////////////// -// Part of this file is taken from the Apache licensed Intel Embree project here: // -// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ // -////////////////////////////////////////////////////////////////////////////////////////// - -#ifndef __GBE_BARRIER_HPP__ -#define __GBE_BARRIER_HPP__ - -#include "sys/condition.hpp" - -namespace gbe -{ - /*! system barrier using operating system */ - class BarrierSys - { - public: - - void init(size_t count) { - this->count = 0; - this->full_size = count; - } - - int wait() { - count_mutex.lock(); - count++; - if (count == full_size) { - count = 0; - cond.broadcast(); - count_mutex.unlock(); - return 1; - } - cond.wait(count_mutex); - count_mutex.unlock(); - return 0; - } - - protected: - size_t count, full_size; - MutexSys count_mutex; - ConditionSys cond; - GBE_CLASS(BarrierSys); - }; - - /* default barrier type */ - class Barrier : public BarrierSys {}; -} - -#endif diff --git a/backend/src/sys/condition.cpp b/backend/src/sys/condition.cpp deleted file mode 100644 index bed37d5b..00000000 --- a/backend/src/sys/condition.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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> - */ - -////////////////////////////////////////////////////////////////////////////////////////// -// Part of this file is taken from the Apache licensed Intel Embree project here: // -// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ // -////////////////////////////////////////////////////////////////////////////////////////// - -#include "sys/condition.hpp" - -#if defined(__WIN32__) -#define WIN32_LEAN_AND_MEAN -#include <windows.h> - -#if defined(__GNUC__) - -namespace gbe -{ - // This is an implementation of POSIX "compatible" condition variables for - // Win32, as described by Douglas C. Schmidt and Irfan Pyarali: - // http://www.cs.wustl.edu/~schmidt/win32-cv-1.html. The code is directly - // readapted from the glfw source code that may be found here: - // http://www.glfw.org - enum { - MINGW32_COND_SIGNAL = 0, - MINGW32_COND_BROADCAST = 1 - }; - - /*! Implement the internal condition variable implementation Mingw lacks */ - struct Mingw32Cond - { - HANDLE events[2]; //<! Signal and broadcast event HANDLEs - unsigned int waiters_count; //<! Count of the number of waiters - CRITICAL_SECTION waiters_count_lock;//!< Serialize access to <waiters_count> - }; - - ConditionSys::ConditionSys () - { - cond = (Mingw32Cond *) GBE_NEW(Mingw32Cond); - ((Mingw32Cond *)cond)->waiters_count = 0; - ((Mingw32Cond *)cond)->events[MINGW32_COND_SIGNAL] = CreateEvent(NULL, FALSE, FALSE, NULL); - ((Mingw32Cond *)cond)->events[MINGW32_COND_BROADCAST] = CreateEvent(NULL, TRUE, FALSE, NULL); - InitializeCriticalSection(&((Mingw32Cond *)cond)->waiters_count_lock); - } - - ConditionSys::~ConditionSys () - { - CloseHandle(((Mingw32Cond *)cond)->events[MINGW32_COND_SIGNAL]); - CloseHandle(((Mingw32Cond *)cond)->events[MINGW32_COND_BROADCAST]); - DeleteCriticalSection(&((Mingw32Cond *)cond)->waiters_count_lock); - GBE_DELETE((Mingw32Cond *)cond); - } - - void ConditionSys::wait(MutexSys& mutex) - { - Mingw32Cond *cv = (Mingw32Cond *) cond; - int result, last_waiter; - DWORD timeout_ms; - - // Avoid race conditions - EnterCriticalSection(&cv->waiters_count_lock); - cv->waiters_count ++; - LeaveCriticalSection(&cv->waiters_count_lock); - - // It's ok to release the mutex here since Win32 manual-reset events - // maintain state when used with SetEvent() - LeaveCriticalSection((CRITICAL_SECTION *) mutex.mutex); - timeout_ms = INFINITE; - - // Wait for either event to become signaled - result = WaitForMultipleObjects(2, cv->events, FALSE, timeout_ms); - - // Check if we are the last waiter - EnterCriticalSection(&cv->waiters_count_lock); - cv->waiters_count --; - last_waiter = (result == WAIT_OBJECT_0 + MINGW32_COND_BROADCAST) && - (cv->waiters_count == 0); - LeaveCriticalSection(&cv->waiters_count_lock); - - // Some thread called broadcast - if (last_waiter) { - // We're the last waiter to be notified or to stop waiting, so - // reset the manual event - ResetEvent(cv->events[MINGW32_COND_BROADCAST]); - } - - // Reacquire the mutex - EnterCriticalSection((CRITICAL_SECTION *) mutex.mutex); - } - - void ConditionSys::broadcast() - { - Mingw32Cond *cv = (Mingw32Cond *) cond; - int have_waiters; - - // Avoid race conditions - EnterCriticalSection(&cv->waiters_count_lock); - have_waiters = cv->waiters_count > 0; - LeaveCriticalSection(&cv->waiters_count_lock); - - if (have_waiters) - SetEvent(cv->events[MINGW32_COND_BROADCAST]); - } -} /* namespace gbe */ -#else - -namespace gbe -{ - /*! system condition using windows API */ - ConditionSys::ConditionSys () { cond = GBE_NEW(CONDITION_VARIABLE); InitializeConditionVariable((CONDITION_VARIABLE*)cond); } - ConditionSys::~ConditionSys() { GBE_DELETE((CONDITION_VARIABLE*)cond); } - void ConditionSys::wait(MutexSys& mutex) { SleepConditionVariableCS((CONDITION_VARIABLE*)cond, (CRITICAL_SECTION*)mutex.mutex, INFINITE); } - void ConditionSys::broadcast() { WakeAllConditionVariable((CONDITION_VARIABLE*)cond); } -} /* namespace gbe */ -#endif /* __GNUC__ */ -#endif /* __WIN32__ */ - -#if defined(__UNIX__) -#include <pthread.h> -namespace gbe -{ - ConditionSys::ConditionSys () { cond = GBE_NEW(pthread_cond_t); pthread_cond_init((pthread_cond_t*)cond,NULL); } - ConditionSys::~ConditionSys() { GBE_DELETE((pthread_cond_t*)cond); } - void ConditionSys::wait(MutexSys& mutex) { pthread_cond_wait((pthread_cond_t*)cond, (pthread_mutex_t*)mutex.mutex); } - void ConditionSys::broadcast() { pthread_cond_broadcast((pthread_cond_t*)cond); } -} /* namespace gbe */ -#endif /* __UNIX__ */ - diff --git a/backend/src/sys/condition.hpp b/backend/src/sys/condition.hpp deleted file mode 100644 index e61e12fe..00000000 --- a/backend/src/sys/condition.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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> - */ - -////////////////////////////////////////////////////////////////////////////////////////// -// Part of this file is taken from the Apache licensed Intel Embree project here: // -// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ // -////////////////////////////////////////////////////////////////////////////////////////// - -#ifndef __GBE_CONDITION_HPP__ -#define __GBE_CONDITION_HPP__ - -#include "sys/mutex.hpp" - -namespace gbe -{ - class ConditionSys - { - public: - ConditionSys(void); - ~ConditionSys(void); - void wait(class MutexSys& mutex); - void broadcast(void); - protected: - void* cond; - }; -} - -#endif /* __GBE_CONDITION_HPP__ */ - diff --git a/backend/src/sys/constants.hpp b/backend/src/sys/constants.hpp deleted file mode 100644 index ecefce19..00000000 --- a/backend/src/sys/constants.hpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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> - */ - -////////////////////////////////////////////////////////////////////////////////////////// -// Part of this file is taken from the Apache licensed Intel Embree project here: // -// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ // -////////////////////////////////////////////////////////////////////////////////////////// - -#ifndef __GBE_CONSTANTS_HPP__ -#define __GBE_CONSTANTS_HPP__ - -#ifndef NULL -#define NULL 0 -#endif - -#include <limits> - -namespace gbe -{ - static struct NullTy { - } null MAYBE_UNUSED; - - static struct TrueTy { - INLINE operator bool( ) const { return true; } - } True MAYBE_UNUSED; - - static struct FalseTy { - INLINE operator bool( ) const { return false; } - } False MAYBE_UNUSED; - - static struct ZeroTy - { - INLINE operator double( ) const { return 0; } - INLINE operator float ( ) const { return 0; } - INLINE operator int64_t ( ) const { return 0; } - INLINE operator uint64_t( ) const { return 0; } - INLINE operator int32_t ( ) const { return 0; } - INLINE operator uint32_t( ) const { return 0; } - INLINE operator int16_t ( ) const { return 0; } - INLINE operator uint16_t( ) const { return 0; } - INLINE operator int8_t ( ) const { return 0; } - INLINE operator uint8_t ( ) const { return 0; } -#ifndef __MSVC__ - INLINE operator size_t( ) const { return 0; } -#endif - - } zero MAYBE_UNUSED; - - static struct OneTy - { - INLINE operator double( ) const { return 1; } - INLINE operator float ( ) const { return 1; } - INLINE operator int64_t ( ) const { return 1; } - INLINE operator uint64_t( ) const { return 1; } - INLINE operator int32_t ( ) const { return 1; } - INLINE operator uint32_t( ) const { return 1; } - INLINE operator int16_t ( ) const { return 1; } - INLINE operator uint16_t( ) const { return 1; } - INLINE operator int8_t ( ) const { return 1; } - INLINE operator uint8_t ( ) const { return 1; } -#ifndef __MSVC__ - INLINE operator size_t( ) const { return 1; } -#endif - } one MAYBE_UNUSED; - - static struct NegInfTy - { - INLINE operator double( ) const { return -std::numeric_limits<double>::infinity(); } - INLINE operator float ( ) const { return -std::numeric_limits<float>::infinity(); } - INLINE operator int64_t ( ) const { return std::numeric_limits<int64_t>::min(); } - INLINE operator uint64_t( ) const { return std::numeric_limits<uint64_t>::min(); } - INLINE operator int32_t ( ) const { return std::numeric_limits<int32_t>::min(); } - INLINE operator uint32_t( ) const { return std::numeric_limits<uint32_t>::min(); } - INLINE operator int16_t ( ) const { return std::numeric_limits<int16_t>::min(); } - INLINE operator uint16_t( ) const { return std::numeric_limits<uint16_t>::min(); } - INLINE operator int8_t ( ) const { return std::numeric_limits<int8_t>::min(); } - INLINE operator uint8_t ( ) const { return std::numeric_limits<uint8_t>::min(); } -#ifndef __MSVC__ - INLINE operator size_t( ) const { return std::numeric_limits<size_t>::min(); } -#endif - - } neg_inf MAYBE_UNUSED; - - static struct PosInfTy - { - INLINE operator double( ) const { return std::numeric_limits<double>::infinity(); } - INLINE operator float ( ) const { return std::numeric_limits<float>::infinity(); } - INLINE operator int64_t ( ) const { return std::numeric_limits<int64_t>::max(); } - INLINE operator uint64_t( ) const { return std::numeric_limits<uint64_t>::max(); } - INLINE operator int32_t ( ) const { return std::numeric_limits<int32_t>::max(); } - INLINE operator uint32_t( ) const { return std::numeric_limits<uint32_t>::max(); } - INLINE operator int16_t ( ) const { return std::numeric_limits<int16_t>::max(); } - INLINE operator uint16_t( ) const { return std::numeric_limits<uint16_t>::max(); } - INLINE operator int8_t ( ) const { return std::numeric_limits<int8_t>::max(); } - INLINE operator uint8_t ( ) const { return std::numeric_limits<uint8_t>::max(); } -#ifndef _WIN32 - INLINE operator size_t( ) const { return std::numeric_limits<size_t>::max(); } -#endif - } inf MAYBE_UNUSED, pos_inf MAYBE_UNUSED; - - static struct NaNTy - { - INLINE operator double( ) const { return std::numeric_limits<double>::quiet_NaN(); } - INLINE operator float ( ) const { return std::numeric_limits<float>::quiet_NaN(); } - } nan MAYBE_UNUSED; - - static struct UlpTy - { - INLINE operator double( ) const { return std::numeric_limits<double>::epsilon(); } - INLINE operator float ( ) const { return std::numeric_limits<float>::epsilon(); } - } ulp MAYBE_UNUSED; - - static struct PiTy - { - INLINE operator double( ) const { return 3.14159265358979323846; } - INLINE operator float ( ) const { return 3.14159265358979323846f; } - } pi MAYBE_UNUSED; - - static struct StepTy { - } step MAYBE_UNUSED; - - static struct EmptyTy { - } empty MAYBE_UNUSED; - - static struct FullTy { - } full MAYBE_UNUSED; - - static const size_t KB = 1024u; - static const size_t MB = KB*KB; - static const size_t GB = KB*MB; -} - -#endif /* __GBE_CONSTANTS_HPP__ */ - diff --git a/backend/src/sys/platform.hpp b/backend/src/sys/platform.hpp index 4f3b3001..735d38f1 100644 --- a/backend/src/sys/platform.hpp +++ b/backend/src/sys/platform.hpp @@ -260,6 +260,10 @@ private: \ /*! Default alignment for the platform */ #define GBE_DEFAULT_ALIGNMENT 16 +/*! Useful constants */ +#define KB 1024 +#define MB (KB*KB) + /*! Portable AlignOf */ template <typename T> struct AlignOf { @@ -336,7 +340,6 @@ private: /// Default Includes and Functions //////////////////////////////////////////////////////////////////////////////// -#include "sys/constants.hpp" #include "sys/alloc.hpp" namespace gbe diff --git a/backend/src/sys/string.cpp b/backend/src/sys/string.cpp deleted file mode 100644 index a63cfd3c..00000000 --- a/backend/src/sys/string.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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 string.cpp - * - * \author Benjamin Segovia <benjamin.segovia@intel.com> - */ -#include "sys/string.hpp" - -#include <cstdio> -#include <cctype> -#include <istream> -#include <fstream> -#include <algorithm> - -namespace std -{ - char to_lower(char c) { return char(tolower(int(c))); } - char to_upper(char c) { return char(toupper(int(c))); } - string strlwr(const string& s) { - string dst(s); - std::transform(dst.begin(), dst.end(), dst.begin(), to_lower); - return dst; - } - string strupr(const string& s) { - string dst(s); - std::transform(dst.begin(), dst.end(), dst.begin(), to_upper); - return dst; - } - -} -namespace gbe -{ - /* $Id: strtok_r.c,v 1.1 2003/12/03 15:22:23 chris_reid Exp $ */ - /* - * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Hgskolan - * (Royal Institute of Technology, Stockholm, Sweden). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - char* tokenize(char *s1, const char *s2, char **lasts) - { - char *ret; - - if (s1 == NULL) - s1 = *lasts; - while(*s1 && strchr(s2, *s1)) - ++s1; - if(*s1 == '\0') - return NULL; - ret = s1; - while(*s1 && !strchr(s2, *s1)) - ++s1; - if(*s1) - *s1++ = '\0'; - *lasts = s1; - return ret; - } - - bool strequal(const char *s1, const char *s2) { - if (strcmp(s1, s2) == 0) return true; - return false; - } - - bool contains(const char *haystack, const char *needle) { - if (strstr(haystack, needle) == NULL) return false; - return true; - } -} - diff --git a/backend/src/sys/string.hpp b/backend/src/sys/string.hpp deleted file mode 100644 index 2b2883a7..00000000 --- a/backend/src/sys/string.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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> - */ - -////////////////////////////////////////////////////////////////////////////////////////// -// Part of this file is taken from the Apache licensed Intel Embree project here: // -// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ // -////////////////////////////////////////////////////////////////////////////////////////// - -#ifndef __GBE_STRING_HPP__ -#define __GBE_STRING_HPP__ - -#include "sys/platform.hpp" - -#include <cstring> -#include <string> -#include <sstream> -#include <fstream> -#include <ostream> - -namespace std -{ - string strlwr(const string& s); - string strupr(const string& s); - template<typename T> INLINE string stringOf(const T& v) { - stringstream s; s << v; return s.str(); - } -} /* namespace std */ - -namespace gbe -{ - /*! Compare two strings */ - bool strequal(const char *s1, const char *s2); - /*! Say if needle is in haystack */ - bool contains(const char *haystack, const char *needle); - /*! Tokenize a string (like strtok_r does) */ - char* tokenize(char *s1, const char *s2, char **lasts); - /*! To append s or not */ - INLINE const char *plural(uint32_t value) { return value > 1 ? "s" : ""; } -} /* namespace gbe */ - -#endif /* __GBE_STRING_HPP__ */ - diff --git a/backend/src/sys/sysinfo.cpp b/backend/src/sys/sysinfo.cpp deleted file mode 100644 index cec306f3..00000000 --- a/backend/src/sys/sysinfo.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * 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> - */ - -////////////////////////////////////////////////////////////////////////////////////////// -// Part of this file is taken from the Apache licensed Intel Embree project here: // -// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ // -////////////////////////////////////////////////////////////////////////////////////////// - -#include "sys/sysinfo.hpp" - -//////////////////////////////////////////////////////////////////////////////// -/// All Platforms -//////////////////////////////////////////////////////////////////////////////// - -namespace gbe -{ - /* return platform name */ - std::string getPlatformName() { -#if defined(__LINUX__) && !defined(__X86_64__) - return "Linux (32bit)"; -#elif defined(__LINUX__) && defined(__X86_64__) - return "Linux (64bit)"; -#elif defined(__FREEBSD__) && !defined(__X86_64__) - return "FreeBSD (32bit)"; -#elif defined(__FREEBSD__) && defined(__X86_64__) - return "FreeBSD (64bit)"; -#elif defined(__CYGWIN__) && !defined(__X86_64__) - return "Cygwin (32bit)"; -#elif defined(__CYGWIN__) && defined(__X86_64__) - return "Cygwin (64bit)"; -#elif defined(__WIN32__) && !defined(__X86_64__) - return "Windows (32bit)"; -#elif defined(__WIN32__) && defined(__X86_64__) - return "Windows (64bit)"; -#elif defined(__MACOSX__) && !defined(__X86_64__) - return "MacOS (32bit)"; -#elif defined(__MACOSX__) && defined(__X86_64__) - return "MacOS (64bit)"; -#elif defined(__UNIX__) && !defined(__X86_64__) - return "Unix (32bit)"; -#elif defined(__UNIX__) && defined(__X86_64__) - return "Unix (64bit)"; -#else - return "Unknown"; -#endif - } -} - -//////////////////////////////////////////////////////////////////////////////// -/// Windows Platform -//////////////////////////////////////////////////////////////////////////////// - -#ifdef __WIN32__ - -#define WIN32_LEAN_AND_MEAN -#include <windows.h> - -namespace gbe -{ - /* get the full path to the running executable */ - std::string getExecutableFileName() { - char filename[1024]; - if (!GetModuleFileName(NULL, filename, sizeof(filename))) return std::string(); - return std::string(filename); - } - - /* return the number of logical threads of the system */ - int getNumberOfLogicalThreads() { - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - return sysinfo.dwNumberOfProcessors; - } -} -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// Linux Platform -//////////////////////////////////////////////////////////////////////////////// - -#ifdef __LINUX__ - -#include <stdio.h> -#include <unistd.h> - -namespace gbe -{ - /* get the full path to the running executable */ - std::string getExecutableFileName() { - char pid[32]; sprintf(pid, "/proc/%d/exe", getpid()); - char buf[1024]; - int bytes = readlink(pid, buf, sizeof(buf)-1); - if (bytes != -1) buf[bytes] = '\0'; - return std::string(buf); - } -} - -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// MacOS Platform -//////////////////////////////////////////////////////////////////////////////// - -#ifdef __MACOSX__ - -#include <mach-o/dyld.h> - -namespace gbe -{ - /* get the full path to the running executable */ - std::string getExecutableFileName() - { - char buf[1024]; - uint32_t_t size = sizeof(buf); - if (_NSGetExecutablePath(buf, &size) != 0) return std::string(); - return std::string(buf); - } -} - -#endif - -//////////////////////////////////////////////////////////////////////////////// -/// Unix Platform -//////////////////////////////////////////////////////////////////////////////// - -#if defined(__UNIX__) - -#include <unistd.h> - -namespace gbe -{ - /* return the number of logical threads of the system */ - int getNumberOfLogicalThreads() { - return sysconf(_SC_NPROCESSORS_CONF); - } -} -#endif - diff --git a/backend/src/sys/sysinfo.hpp b/backend/src/sys/sysinfo.hpp deleted file mode 100644 index a4e5b84f..00000000 --- a/backend/src/sys/sysinfo.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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> - */ - -////////////////////////////////////////////////////////////////////////////////////////// -// Part of this file is taken from the Apache licensed Intel Embree project here: // -// http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/ // -////////////////////////////////////////////////////////////////////////////////////////// - -#ifndef __GBE_SYSINFO_HPP__ -#define __GBE_SYSINFO_HPP__ - -#include "sys/platform.hpp" - -#include <string> - -namespace gbe -{ - /*! get the full path to the running executable */ - std::string getExecutableFileName(); - /*! return platform name */ - std::string getPlatformName(); - /*! return the number of logical threads of the system */ - int getNumberOfLogicalThreads(); -} - -#endif |
