diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d2e8007 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,86 @@ +cmake_minimum_required(VERSION 3.1) +project(QPULib CXX) +set(CMAKE_CXX_STANDARD 14) + +option(BUILD_EXAMPLES "Build all examples in the example directory" OFF) +option(ENABLE_DEBUG "Output debug information from QPULib" OFF) +option(ENABLE_QPU "Enable QPU (rpi only), otherwise emulate" OFF) + +if(${ENABLE_DEBUG}) + set(QPULIB_DEBUG 1) +endif() + +if(${ENABLE_QPU}) + set(QPULIB_QPU_MODE 1) +else() + set(QPULIB_EMULATION_MODE 1) +endif() + +STRING(REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Lib/qpulib_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/qpulib_config.h) +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/Lib + ${CMAKE_CURRENT_BINARY_DIR} +) + +set( + SOURCES + + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Kernel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Source/Syntax.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Source/Int.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Source/Float.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Source/Stmt.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Source/Pretty.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Source/Translate.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Source/Interpreter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Source/Gen.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Target/Syntax.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Target/SmallLiteral.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Target/Pretty.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Target/RemoveLabels.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Target/CFG.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Target/Liveness.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Target/RegAlloc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Target/ReachingDefs.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Target/Subst.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Target/LiveRangeSplit.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Target/Satisfy.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Target/LoadStore.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Target/Emulator.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/Target/Encode.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/VideoCore/Mailbox.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/VideoCore/Invoke.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/VideoCore/VideoCore.cpp +) + +add_library(qpu.a STATIC ${SOURCES}) +add_library(qpu.so SHARED ${SOURCES}) + +set_target_properties(qpu.a PROPERTIES OUTPUT_NAME qpu) +set_target_properties(qpu.so PROPERTIES OUTPUT_NAME qpu) + +install(TARGETS + qpu.a qpu.so + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) + +install(DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR}/Lib/ + DESTINATION include/QPULib + FILES_MATCHING PATTERN "*.h" +) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/qpulib_config.h + DESTINATION include +) + +if(${BUILD_EXAMPLES}) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Examples) +endif() diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt new file mode 100644 index 0000000..d0dbe5f --- /dev/null +++ b/Examples/CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 3.1) +project(QPULib_Examples CXX) +set(CMAKE_CXX_STANDARD 14) + +macro(add_executable _name) + _add_executable(${ARGV}) + if(TARGET ${_name}) + # link libqpu statically because we don't know if it has been installed yet + target_link_libraries(${_name} libqpu.a) + + # ensure that the qpu library is built first, no matter if static or not + add_dependencies(${_name} qpu.so) + add_dependencies(${_name} qpu.a) + endif() +endmacro() + +STRING(REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../Lib) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../lib) + +add_executable(AutoTest ${CMAKE_CURRENT_SOURCE_DIR}/AutoTest.cpp) +add_executable(DMA ${CMAKE_CURRENT_SOURCE_DIR}/DMA.cpp) +add_executable(GCD ${CMAKE_CURRENT_SOURCE_DIR}/GCD.cpp) +add_executable(HeatMap ${CMAKE_CURRENT_SOURCE_DIR}/HeatMap.cpp) +add_executable(HeatMapScalar ${CMAKE_CURRENT_SOURCE_DIR}/HeatMapScalar.cpp) +add_executable(Hello ${CMAKE_CURRENT_SOURCE_DIR}/Hello.cpp) +add_executable(ID ${CMAKE_CURRENT_SOURCE_DIR}/ID.cpp) +add_executable(Mandelbrot ${CMAKE_CURRENT_SOURCE_DIR}/Mandelbrot.cpp) +add_executable(MultiTri ${CMAKE_CURRENT_SOURCE_DIR}/MultiTri.cpp) +add_executable(OET ${CMAKE_CURRENT_SOURCE_DIR}/OET.cpp) +add_executable(Print ${CMAKE_CURRENT_SOURCE_DIR}/Print.cpp) +add_executable(ReqRecv ${CMAKE_CURRENT_SOURCE_DIR}/ReqRecv.cpp) +add_executable(Rot3D ${CMAKE_CURRENT_SOURCE_DIR}/Rot3D.cpp) +add_executable(Sort ${CMAKE_CURRENT_SOURCE_DIR}/Sort.cpp) +add_executable(Tri ${CMAKE_CURRENT_SOURCE_DIR}/Tri.cpp) +add_executable(TriFloat ${CMAKE_CURRENT_SOURCE_DIR}/TriFloat.cpp) diff --git a/Lib/Kernel.h b/Lib/Kernel.h index b87bb07..7adb683 100644 --- a/Lib/Kernel.h +++ b/Lib/Kernel.h @@ -1,6 +1,8 @@ #ifndef _QPULIB_KERNEL_H_ #define _QPULIB_KERNEL_H_ +#include "qpulib_config.h" + #include "Source/Interpreter.h" #include "Target/Emulator.h" #include "Target/Encode.h" @@ -10,19 +12,18 @@ #include "Source/Pretty.h" #include "Target/Pretty.h" - namespace QPULib { // ============================================================================ // Modes of operation // ============================================================================ -// Two important compile-time macros are EMULATION_MODE and QPU_MODE. -// With -D EMULATION_MODE, QPULib can be compiled for any architecture. -// With -D QPU_MODE, QPULib can be compiled only for the Raspberry Pi. +// Two important compile-time macros are QPULIB_EMULATION_MODE and QPULIB_QPU_MODE. +// With -D QPULIB_EMULATION_MODE, QPULib can be compiled for any architecture. +// With -D QPULIB_QPU_MODE, QPULib can be compiled only for the Raspberry Pi. // At least one of these macros must be defined. -// IN EMULATION_MODE a memory pool is used for allocating data that +// IN QPULIB_EMULATION_MODE a memory pool is used for allocating data that // can be read by kernels. Otherwise, a mailbox interface to the // VideoCore is used to allocate memory. In both cases, see // 'VideoCore/SharedArray.h'. @@ -30,19 +31,19 @@ namespace QPULib { // The 'Kernel' class provides various ways to invoke a kernel: // // * qpu(...) invoke kernel on physical QPUs -// (only available in QPU_MODE) +// (only available in QPULIB_QPU_MODE) // * emulate(...) invoke kernel using target code emulator -// (only available in EMULATION_MODE) +// (only available in QPULIB_EMULATION_MODE) // * interpret(...) invoke kernel using source code interpreter -// (only available in EMULATION_MODE) -// * call(...) in EMULATION_MODE, same as emulate(...) -// in QPU_MODE, same as qpu(...) -// in EMULATION_MODE *and* QPU_MODE, same as emulate(...) +// (only available in QPULIB_EMULATION_MODE) +// * call(...) in QPULIB_EMULATION_MODE, same as emulate(...) +// in QPULIB_QPU_MODE, same as qpu(...) +// in QPULIB_EMULATION_MODE *and* QPULIB_QPU_MODE, same as emulate(...) -// Notice it is OK to compile with both -D EMULATION_MODE *and* -// -D QPU_MODE. This feature is provided for doing equivalance +// Notice it is OK to compile with both -D QPULIB_EMULATION_MODE *and* +// -D QPULIB_QPU_MODE. This feature is provided for doing equivalance // testing between the physical QPU and the QPU emulator. However, -// EMULATION_MODE introduces a performance penalty and should be used +// QPULIB_EMULATION_MODE introduces a performance penalty and should be used // only for testing and debugging purposes. // Maximum number of kernel parameters allowed @@ -174,7 +175,7 @@ template struct Kernel { int numQPUs; // Memory region for QPU code and parameters - #ifdef QPU_MODE + #ifdef QPULIB_QPU_MODE SharedArray* qpuCodeMem; int qpuCodeMemOffset; #endif @@ -209,8 +210,8 @@ template struct Kernel { Stmt* body = stmtStack.top(); stmtStack.pop(); - // For EMULATION_MODE, the following is needed in the interpreter - // For QPU_MODE, it is here in case a pretty-print is requested + // For QPULIB_EMULATION_MODE, the following is needed in the interpreter + // For QPULIB_QPU_MODE, it is here in case a pretty-print is requested sourceCode = body; // Compile @@ -219,7 +220,7 @@ template struct Kernel { // Remember the number of variables used numVars = getFreshVarCount(); - #ifdef QPU_MODE + #ifdef QPULIB_QPU_MODE enableQPUs(); // Allocate code mem @@ -242,7 +243,7 @@ template struct Kernel { #endif } - #ifdef EMULATION_MODE + #ifdef QPULIB_EMULATION_MODE template void emu(us... args) { // Pass params, checking arguments types us against parameter types ts uniforms.clear(); @@ -259,7 +260,7 @@ template struct Kernel { #endif // Invoke the interpreter - #ifdef EMULATION_MODE + #ifdef QPULIB_EMULATION_MODE template void interpret(us... args) { // Pass params, checking arguments types us against parameter types ts uniforms.clear(); @@ -276,7 +277,7 @@ template struct Kernel { #endif // Invoke kernel on physical QPU hardware - #ifdef QPU_MODE + #ifdef QPULIB_QPU_MODE template void qpu(us... args) { // Pass params, checking arguments types us against parameter types ts uniforms.clear(); @@ -289,10 +290,10 @@ template struct Kernel { // Invoke the kernel template void call(us... args) { - #ifdef EMULATION_MODE + #ifdef QPULIB_EMULATION_MODE emu(args...); #else - #ifdef QPU_MODE + #ifdef QPULIB_QPU_MODE qpu(args...); #endif #endif @@ -310,7 +311,7 @@ template struct Kernel { // Deconstructor ~Kernel() { - #ifdef QPU_MODE + #ifdef QPULIB_QPU_MODE delete qpuCodeMem; disableQPUs(); #endif diff --git a/Lib/QPULib.h b/Lib/QPULib.h index 352f018..27040ee 100644 --- a/Lib/QPULib.h +++ b/Lib/QPULib.h @@ -1,6 +1,7 @@ #ifndef _QPULIB_H_ #define _QPULIB_H_ +#include "qpulib_config.h" #include "Source/Int.h" #include "Source/Float.h" #include "Source/Ptr.h" diff --git a/Lib/Source/Cond.h b/Lib/Source/Cond.h index 523dc40..84f50c7 100644 --- a/Lib/Source/Cond.h +++ b/Lib/Source/Cond.h @@ -1,8 +1,8 @@ #ifndef _QPULIB_SOURCE_COND_H_ #define _QPULIB_SOURCE_COND_H_ -#include "Source/Syntax.h" -#include "Source/Int.h" +#include "../Source/Syntax.h" +#include "../Source/Int.h" namespace QPULib { diff --git a/Lib/Source/Float.h b/Lib/Source/Float.h index aec80cd..666291d 100644 --- a/Lib/Source/Float.h +++ b/Lib/Source/Float.h @@ -4,7 +4,7 @@ #define _QPULIB_SOURCE_FLOAT_H_ #include -#include "Source/Syntax.h" +#include "../Source/Syntax.h" namespace QPULib { diff --git a/Lib/Source/Gen.h b/Lib/Source/Gen.h index 15a250a..5f6f3b4 100644 --- a/Lib/Source/Gen.h +++ b/Lib/Source/Gen.h @@ -3,8 +3,8 @@ #ifndef _QPULIB_GEN_H_ #define _QPULIB_GEN_H_ -#include "Common/Seq.h" -#include "Source/Syntax.h" +#include "../Common/Seq.h" +#include "../Source/Syntax.h" namespace QPULib { diff --git a/Lib/Source/Int.h b/Lib/Source/Int.h index d78e613..f29fdd5 100644 --- a/Lib/Source/Int.h +++ b/Lib/Source/Int.h @@ -4,8 +4,8 @@ #define _QPULIB_SOURCE_INT_H_ #include -#include "Source/Syntax.h" -#include "Source/Float.h" +#include "../Source/Syntax.h" +#include "../Source/Float.h" namespace QPULib { diff --git a/Lib/Source/Interpreter.h b/Lib/Source/Interpreter.h index 157198d..1d61a4d 100644 --- a/Lib/Source/Interpreter.h +++ b/Lib/Source/Interpreter.h @@ -2,15 +2,15 @@ #define _QPULIB_INTERPRETER_H_ #include -#include "Common/Seq.h" -#include "Source/Syntax.h" +#include "../Common/Seq.h" +#include "../Source/Syntax.h" // The interpreter works in a similar way to the emulator. The // difference is that the former operates on source code and the // latter on target code. We reuse a number of concepts of the // emulator in the interpreter. -#include "Target/Emulator.h" +#include "../Target/Emulator.h" namespace QPULib { diff --git a/Lib/Source/Pretty.h b/Lib/Source/Pretty.h index bfa4971..4f0d51e 100644 --- a/Lib/Source/Pretty.h +++ b/Lib/Source/Pretty.h @@ -1,7 +1,7 @@ #ifndef _QPULIB_SOURCE_PRETTY_H_ #define _QPULIB_SOURCE_PRETTY_H_ -#include "Source/Syntax.h" +#include "../Source/Syntax.h" namespace QPULib { diff --git a/Lib/Source/Ptr.h b/Lib/Source/Ptr.h index 4f31edd..12ba0de 100644 --- a/Lib/Source/Ptr.h +++ b/Lib/Source/Ptr.h @@ -5,7 +5,7 @@ #define _QPULIB_SOURCE_PTR_H_ #include -#include "Source/Syntax.h" +#include "../Source/Syntax.h" namespace QPULib { diff --git a/Lib/Source/Stmt.h b/Lib/Source/Stmt.h index 19c1b39..220ae27 100644 --- a/Lib/Source/Stmt.h +++ b/Lib/Source/Stmt.h @@ -1,10 +1,10 @@ #ifndef _QPULIB_SOURCE_STMT_H_ #define _QPULIB_SOURCE_STMT_H_ -#include "Source/Cond.h" -#include "Source/Syntax.h" -#include "Source/Ptr.h" -#include "Source/StmtExtra.h" +#include "../Source/Cond.h" +#include "../Source/Syntax.h" +#include "../Source/Ptr.h" +#include "../Source/StmtExtra.h" namespace QPULib { diff --git a/Lib/Source/Syntax.h b/Lib/Source/Syntax.h index f65e324..ec1eb47 100644 --- a/Lib/Source/Syntax.h +++ b/Lib/Source/Syntax.h @@ -3,8 +3,8 @@ #ifndef _QPULIB_SOURCE_SYNTAX_H_ #define _QPULIB_SOURCE_SYNTAX_H_ -#include "Common/Heap.h" -#include "Common/Stack.h" +#include "../Common/Heap.h" +#include "../Common/Stack.h" namespace QPULib { diff --git a/Lib/Source/Translate.h b/Lib/Source/Translate.h index 8f55f64..f61ecdb 100644 --- a/Lib/Source/Translate.h +++ b/Lib/Source/Translate.h @@ -1,9 +1,9 @@ #ifndef _QPULIB_TRANSLATE_H_ #define _QPULIB_TRANSLATE_H_ -#include "Common/Seq.h" -#include "Source/Syntax.h" -#include "Target/Syntax.h" +#include "../Common/Seq.h" +#include "../Source/Syntax.h" +#include "../Target/Syntax.h" namespace QPULib { diff --git a/Lib/Target/CFG.h b/Lib/Target/CFG.h index a1aa09c..847697c 100644 --- a/Lib/Target/CFG.h +++ b/Lib/Target/CFG.h @@ -3,8 +3,8 @@ #ifndef _QPULIB_CFG_H_ #define _QPULIB_CFG_H_ -#include "Common/Seq.h" -#include "Target/Syntax.h" +#include "../Common/Seq.h" +#include "../Target/Syntax.h" namespace QPULib { diff --git a/Lib/Target/Emulator.h b/Lib/Target/Emulator.h index 7fa85d0..2b493cd 100644 --- a/Lib/Target/Emulator.h +++ b/Lib/Target/Emulator.h @@ -2,9 +2,9 @@ #define _QPULIB_EMULATOR_H_ #include -#include "Common/Seq.h" -#include "Common/Queue.h" -#include "Target/Syntax.h" +#include "../Common/Seq.h" +#include "../Common/Queue.h" +#include "../Target/Syntax.h" #define NUM_LANES 16 #define MAX_QPUS 12 diff --git a/Lib/Target/Encode.h b/Lib/Target/Encode.h index 01ca2ca..96ee408 100644 --- a/Lib/Target/Encode.h +++ b/Lib/Target/Encode.h @@ -2,8 +2,8 @@ #define _QPULIB_ENCODE_H_ #include -#include "Target/Syntax.h" -#include "Common/Seq.h" +#include "../Target/Syntax.h" +#include "../Common/Seq.h" namespace QPULib { diff --git a/Lib/Target/LiveRangeSplit.h b/Lib/Target/LiveRangeSplit.h index 21ec0bf..0e61270 100644 --- a/Lib/Target/LiveRangeSplit.h +++ b/Lib/Target/LiveRangeSplit.h @@ -1,9 +1,9 @@ #ifndef _QPULIB_LIVERANGESPLIT_H_ #define _QPULIB_LIVERANGESPLIT_H_ -#include "Common/Seq.h" -#include "Target/CFG.h" -#include "Target/Syntax.h" +#include "../Common/Seq.h" +#include "../Target/CFG.h" +#include "../Target/Syntax.h" namespace QPULib { diff --git a/Lib/Target/Liveness.h b/Lib/Target/Liveness.h index 3faa53e..7ca91d2 100644 --- a/Lib/Target/Liveness.h +++ b/Lib/Target/Liveness.h @@ -3,9 +3,9 @@ #ifndef _QPULIB_LIVENESS_H_ #define _QPULIB_LIVENESS_H_ -#include "Common/Seq.h" -#include "Target/Syntax.h" -#include "Target/CFG.h" +#include "../Common/Seq.h" +#include "../Target/Syntax.h" +#include "../Target/CFG.h" namespace QPULib { diff --git a/Lib/Target/LoadStore.h b/Lib/Target/LoadStore.h index a0fb9e0..f47bc29 100644 --- a/Lib/Target/LoadStore.h +++ b/Lib/Target/LoadStore.h @@ -1,9 +1,9 @@ #ifndef _QPULIB_LOADSTORE_H_ #define _QPULIB_LOADSTORE_H_ -#include "Common/Seq.h" -#include "Target/Syntax.h" -#include "Source/Syntax.h" +#include "../Common/Seq.h" +#include "../Target/Syntax.h" +#include "../Source/Syntax.h" namespace QPULib { diff --git a/Lib/Target/Pretty.h b/Lib/Target/Pretty.h index a159741..cc84b60 100644 --- a/Lib/Target/Pretty.h +++ b/Lib/Target/Pretty.h @@ -2,7 +2,7 @@ #define _QPULIB_TARGET_PRETTY_H_ #include -#include "Target/Syntax.h" +#include "../Target/Syntax.h" namespace QPULib { diff --git a/Lib/Target/ReachingDefs.h b/Lib/Target/ReachingDefs.h index 99b731e..9e4b29d 100644 --- a/Lib/Target/ReachingDefs.h +++ b/Lib/Target/ReachingDefs.h @@ -3,9 +3,9 @@ #ifndef _QPULIB_REACHINGDEFS_H_ #define _QPULIB_REACHINGDEFS_H_ -#include "Common/Seq.h" -#include "Target/Syntax.h" -#include "Target/CFG.h" +#include "../Common/Seq.h" +#include "../Target/Syntax.h" +#include "../Target/CFG.h" namespace QPULib { diff --git a/Lib/Target/RegAlloc.h b/Lib/Target/RegAlloc.h index d60fffe..600c6c8 100644 --- a/Lib/Target/RegAlloc.h +++ b/Lib/Target/RegAlloc.h @@ -1,10 +1,10 @@ #ifndef _QPULIB_REGALLOC_H_ #define _QPULIB_REGALLOC_H_ -#include "Target/CFG.h" -#include "Target/Liveness.h" -#include "Target/Syntax.h" -#include "Common/Seq.h" +#include "../Target/CFG.h" +#include "../Target/Liveness.h" +#include "../Target/Syntax.h" +#include "../Common/Seq.h" namespace QPULib { diff --git a/Lib/Target/RemoveLabels.h b/Lib/Target/RemoveLabels.h index d5be3ae..4825b58 100644 --- a/Lib/Target/RemoveLabels.h +++ b/Lib/Target/RemoveLabels.h @@ -1,10 +1,10 @@ #ifndef _QPULIB_REMOVELABELS_H_ #define _QPULIB_REMOVELABELS_H_ -#include "Target/Syntax.h" -#include "Target/CFG.h" -#include "Target/Liveness.h" -#include "Common/Seq.h" +#include "../Target/Syntax.h" +#include "../Target/CFG.h" +#include "../Target/Liveness.h" +#include "../Common/Seq.h" namespace QPULib { diff --git a/Lib/Target/Satisfy.h b/Lib/Target/Satisfy.h index 607f5b7..761c126 100644 --- a/Lib/Target/Satisfy.h +++ b/Lib/Target/Satisfy.h @@ -1,8 +1,8 @@ #ifndef _QPULIB_SATISFY_H_ #define _QPULIB_SATISFY_H_ -#include "Target/Syntax.h" -#include "Target/CFG.h" +#include "../Target/Syntax.h" +#include "../Target/CFG.h" namespace QPULib { diff --git a/Lib/Target/SmallLiteral.h b/Lib/Target/SmallLiteral.h index afaa91e..aee421d 100644 --- a/Lib/Target/SmallLiteral.h +++ b/Lib/Target/SmallLiteral.h @@ -1,8 +1,8 @@ #ifndef _QPULIB_SMALL_LITERAL_H_ #define _QPULIB_SMALL_LITERAL_H_ -#include "Source/Syntax.h" -#include "Target/Emulator.h" +#include "../Source/Syntax.h" +#include "../Target/Emulator.h" namespace QPULib { diff --git a/Lib/Target/Subst.h b/Lib/Target/Subst.h index 3ef8203..b7bc3b6 100644 --- a/Lib/Target/Subst.h +++ b/Lib/Target/Subst.h @@ -1,7 +1,7 @@ #ifndef _QPULIB_SUBST_H_ #define _QPULIB_SUBST_H_ -#include "Target/Syntax.h" +#include "../Target/Syntax.h" namespace QPULib { diff --git a/Lib/VideoCore/Invoke.cpp b/Lib/VideoCore/Invoke.cpp index 5e04893..f517731 100644 --- a/Lib/VideoCore/Invoke.cpp +++ b/Lib/VideoCore/Invoke.cpp @@ -1,6 +1,6 @@ -#ifdef QPU_MODE - #include "VideoCore/Invoke.h" + +#ifdef QPULIB_QPU_MODE #include "VideoCore/Mailbox.h" #include "VideoCore/VideoCore.h" @@ -53,4 +53,4 @@ void invoke( } // namespace QPULib -#endif // QPU_MODE +#endif // QPULIB_QPU_MODE diff --git a/Lib/VideoCore/Invoke.h b/Lib/VideoCore/Invoke.h index e3e0e18..706608a 100644 --- a/Lib/VideoCore/Invoke.h +++ b/Lib/VideoCore/Invoke.h @@ -1,10 +1,11 @@ -#ifdef QPU_MODE - #ifndef _QPULIB_INVOKE_H_ #define _QPULIB_INVOKE_H_ -#include "Common/Seq.h" -#include "VideoCore/SharedArray.h" +#include "qpulib_config.h" + +#ifdef QPULIB_QPU_MODE +#include "../Common/Seq.h" +#include "../VideoCore/SharedArray.h" #include namespace QPULib { @@ -17,5 +18,5 @@ void invoke( } // namespace QPULib +#endif // QPULIB_QPU_MODE #endif // _QPULIB_INVOKE_H_ -#endif // QPU_MODE diff --git a/Lib/VideoCore/RegisterMap.cpp b/Lib/VideoCore/RegisterMap.cpp index 6050e11..c65be56 100644 --- a/Lib/VideoCore/RegisterMap.cpp +++ b/Lib/VideoCore/RegisterMap.cpp @@ -1,6 +1,6 @@ -#ifdef QPU_MODE - #include "RegisterMap.h" +#ifdef QPULIB_QPU_MODE + #include #include #include @@ -97,4 +97,4 @@ void RegisterMap::check_page_align(unsigned addr) { } // namespace QPULib -#endif // QPU_MODE +#endif // QPULIB_QPU_MODE diff --git a/Lib/VideoCore/RegisterMap.h b/Lib/VideoCore/RegisterMap.h index 5c293f2..edc0330 100644 --- a/Lib/VideoCore/RegisterMap.h +++ b/Lib/VideoCore/RegisterMap.h @@ -1,7 +1,9 @@ -#ifdef QPU_MODE - #ifndef _QPULIB_REGISTERMAP_H #define _QPULIB_REGISTERMAP_H + +#include "qpulib_config.h" +#ifdef QPULIB_QPU_MODE + #include #include @@ -44,6 +46,5 @@ class RegisterMap { } // namespace QPULib +#endif // QPULIB_QPU_MODE #endif // _QPULIB_REGISTERMAP_H - -#endif // QPU_MODE diff --git a/Lib/VideoCore/SharedArray.h b/Lib/VideoCore/SharedArray.h index 8d7736e..62ce66c 100644 --- a/Lib/VideoCore/SharedArray.h +++ b/Lib/VideoCore/SharedArray.h @@ -1,33 +1,35 @@ #ifndef _QPULIB_SHAREDARRAY_H_ #define _QPULIB_SHAREDARRAY_H_ -#if !defined(QPU_MODE) && !defined(EMULATION_MODE) +#include "qpulib_config.h" + +#if !defined(QPULIB_QPU_MODE) && !defined(QPULIB_EMULATION_MODE) // // Detect mode, set default if none defined. // This is the best place to test it in the code, since it's // the first of the header files to be compiled. // -#pragma message "WARNING: QPU_MODE and EMULATION_MODE not defined, defaulting to EMULATION_MODE" -#define EMULATION_MODE +#pragma message "WARNING: QPULIB_QPU_MODE and QPULIB_EMULATION_MODE not defined, defaulting to QPULIB_EMULATION_MODE" +#define QPULIB_EMULATION_MODE #endif #include #include #include -#include "VideoCore/Mailbox.h" -#include "VideoCore/VideoCore.h" +#include "../VideoCore/Mailbox.h" +#include "../VideoCore/VideoCore.h" namespace QPULib { -#ifdef EMULATION_MODE +#ifdef QPULIB_EMULATION_MODE // ============================================================================ // Emulation mode // ============================================================================ -// When in EMULATION_MODE allocate memory from a pre-allocated pool. +// When in QPULIB_EMULATION_MODE allocate memory from a pre-allocated pool. -#include "Target/Emulator.h" +#include "../Target/Emulator.h" // Implementation template class SharedArray { diff --git a/Lib/VideoCore/VideoCore.cpp b/Lib/VideoCore/VideoCore.cpp index 24e6bd7..e58abe2 100644 --- a/Lib/VideoCore/VideoCore.cpp +++ b/Lib/VideoCore/VideoCore.cpp @@ -1,10 +1,11 @@ -#ifdef QPU_MODE +#include "VideoCore.h" + +#ifdef QPULIB_QPU_MODE +#include "Mailbox.h" #include #include #include -#include "VideoCore/VideoCore.h" -#include "VideoCore/Mailbox.h" namespace QPULib { @@ -46,4 +47,4 @@ void disableQPUs() } // namespace QPULib -#endif // QPU_MODE +#endif // QPULIB_QPU_MODE diff --git a/Lib/VideoCore/VideoCore.h b/Lib/VideoCore/VideoCore.h index 27ba899..d318e46 100644 --- a/Lib/VideoCore/VideoCore.h +++ b/Lib/VideoCore/VideoCore.h @@ -1,8 +1,9 @@ -#ifdef QPU_MODE - #ifndef _QPULIB_VIDEOCORE_H_ #define _QPULIB_VIDEOCORE_H_ +#include "qpulib_config.h" +#ifdef QPULIB_QPU_MODE + namespace QPULib { // Globals @@ -16,5 +17,5 @@ void disableQPUs(); } // namespace QPULib +#endif // QPULIB_QPU_MODE #endif // _QPULIB_VIDEOCORE_H_ -#endif // QPU_MODE diff --git a/Lib/qpulib_config.h.in b/Lib/qpulib_config.h.in new file mode 100644 index 0000000..ff7b375 --- /dev/null +++ b/Lib/qpulib_config.h.in @@ -0,0 +1,8 @@ +#ifndef _QPULIB_CONFIG_H +#define _QPULIB_CONFIG_H + +#cmakedefine QPULIB_DEBUG +#cmakedefine QPULIB_QPU_MODE +#cmakedefine QPULIB_EMULATION_MODE + +#endif diff --git a/README.md b/README.md index a5277aa..6198d63 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ introduces and documents QPULib. For build instructions, see the * [Scalar version](#scalar-version-2) * [Vector version](#vector-version) * [Performance](#performance-1) +* [Compiling](#compiling) * [References](#user-content-references) ## Background @@ -668,6 +669,20 @@ Times taken to simulate a 512x512 surface for 2000 steps: Vector | 2 | 24.91 | Vector | 4 | 20.36 | +### Compiling + +Compiling this project requires CMake (>=3.1). + + * git clone ${clone url} + * cd QPULib + * cmake + * -DENABLE_QPU=ON will enable the QPU (rpi only) + * -DBUILD_EXAMPLES=ON will build all examples in the Examples subdirectory + * -DENABLE_DEBUG=ON will cause QPULib to compile with debug output to stdout + * make + * (optional) sudo make install # installs libraries and headers to CMAKE_INSTALL_PREFIX/{lib,include} + +This will create two directories, lib and bin, together with some CMake cache files. The examples, if enabled, are statically compiled and put into the bin directory, the lib directory contains both libqpu.a and libqpu.so for dynamic and static linking. ## References diff --git a/Tests/testMain.cpp b/Tests/testMain.cpp index 6eb9c08..61cf611 100644 --- a/Tests/testMain.cpp +++ b/Tests/testMain.cpp @@ -11,12 +11,12 @@ #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file #include "catch.hpp" #include -#ifdef QPU_MODE +#ifdef QPULIB_QPU_MODE #include "../Lib/Target/Emulator.h" // MAX_QPUS #include "../Lib/VideoCore/RegisterMap.h" using RegMap = QPULib::RegisterMap; -#endif // QPU_MODE +#endif // QPULIB_QPU_MODE // @@ -28,7 +28,7 @@ using RegMap = QPULib::RegisterMap; #define POSTFIX_DEBUG "" #endif -#ifdef QPU_MODE +#ifdef QPULIB_QPU_MODE // #pragma message "QPU mode enabled" #define POSTFIX_QPU "-qpu" #else @@ -61,7 +61,7 @@ TEST_CASE("Detect platform scripts should both return the same thing", "[cmdline } -#ifdef QPU_MODE +#ifdef QPULIB_QPU_MODE TEST_CASE("Test correct working of RegisterMap", "[regmap]") { @@ -79,4 +79,4 @@ TEST_CASE("Test correct working of RegisterMap", "[regmap]") { } } -#endif // QPU_MODE +#endif // QPULIB_QPU_MODE diff --git a/Tools/detectPlatform.cpp b/Tools/detectPlatform.cpp index 25afbea..02429fc 100644 --- a/Tools/detectPlatform.cpp +++ b/Tools/detectPlatform.cpp @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) { return 1; } -#ifdef QPU_MODE +#ifdef QPULIB_QPU_MODE // Show hardware revision code int mb = getMailbox(); unsigned revision = get_version(mb); @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) { } else { printf("You can see more if you use sudo\n"); } -#endif // QPU_MODE +#endif // QPULIB_QPU_MODE return 0; }