From 4bbe0402a0c74c5098b1e1f82f136ef777ab6ec5 Mon Sep 17 00:00:00 2001 From: Micah Date: Sat, 28 Dec 2019 19:31:33 -0600 Subject: [PATCH 01/12] Compile with CMake Works on Ubuntu, but not Windows --- .gitignore | 45 ++++++++++++++++++++++ CMakeLists.txt | 4 ++ Lib/CMakeLists.txt | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 Lib/CMakeLists.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..91f1eb2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,45 @@ +# Cmake +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b0189ac --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,4 @@ + +# Include Source files. + +add_subdirectory ("Lib") \ No newline at end of file diff --git a/Lib/CMakeLists.txt b/Lib/CMakeLists.txt new file mode 100644 index 0000000..1658485 --- /dev/null +++ b/Lib/CMakeLists.txt @@ -0,0 +1,96 @@ + + +#QPULib uses assert statements that throw errors when compiling with g++ on platforms other than the Pi +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_definitions(-fpermissive) +endif() + + + +#file(GLOB_RECURSE QPULIB_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp") +#message(STATUS "QPULib library source files: ${QPULIB_SOURCES}") +#file(GLOB_RECURSE QPULIB_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h" "*.hpp") + + + +add_library(QPULib "") + +#Compile differently for the Raspberry Pi +include(CheckIncludeFile) +CHECK_INCLUDE_FILE(/opt/vc/include/bcm_host.h BCMHOST) +if (BCMHOST) #This is a Pi + message(STATUS "This is a Pi") + #Set precompiler flags + add_definitions(-DEMULATION_MODE) + #Compile stuff + target_sources(QPULib + PRIVATE + Kernel.cpp + Source/Float.cpp + Source/Gen.cpp + Source/Int.cpp + Source/Interpreter.cpp + Source/Pretty.cpp + Source/Stmt.cpp + Source/Syntax.cpp + Source/Translate.cpp + Target/CFG.cpp + Target/Emulator.cpp + Target/Encode.cpp + Target/LiveRangeSplit.cpp + Target/Liveness.cpp + Target/LoadStore.cpp + Target/Pretty.cpp + Target/ReachingDefs.cpp + Target/RegAlloc.cpp + Target/RemoveLabels.cpp + Target/Satisfy.cpp + Target/SmallLiteral.cpp + Target/Subst.cpp + Target/Syntax.cpp + VideoCore/Invoke.cpp + VideoCore/Mailbox.cpp + VideoCore/VideoCore.cpp + ) +else() #Not compiling on the Pi + message(STATUS "This is not a Pi") + #Add precompiler definitions + add_definitions(-DEMULATION_MODE) + #Compile stuff + target_sources(QPULib + PRIVATE + Kernel.cpp + Source/Float.cpp + Source/Gen.cpp + Source/Int.cpp + Source/Interpreter.cpp + Source/Pretty.cpp + Source/Stmt.cpp + Source/Syntax.cpp + Source/Translate.cpp + Target/CFG.cpp + Target/Emulator.cpp + Target/Encode.cpp + Target/LiveRangeSplit.cpp + Target/Liveness.cpp + Target/LoadStore.cpp + Target/Pretty.cpp + Target/ReachingDefs.cpp + Target/RegAlloc.cpp + Target/RemoveLabels.cpp + Target/Satisfy.cpp + Target/SmallLiteral.cpp + Target/Subst.cpp + Target/Syntax.cpp + ) +endif() + +target_include_directories(QPULib + PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/Source + ${CMAKE_CURRENT_LIST_DIR}/Common + ${CMAKE_CURRENT_LIST_DIR}/Target + ${CMAKE_CURRENT_LIST_DIR}/VideoCore + ${CMAKE_CURRENT_LIST_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ) \ No newline at end of file From cd7b0a77130cdf99ec3faaba7557f3c24542282f Mon Sep 17 00:00:00 2001 From: Micah Date: Sat, 28 Dec 2019 19:32:29 -0600 Subject: [PATCH 02/12] Update .gitignore Remove some output files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 91f1eb2..ed51497 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,5 @@ _deps *.exe *.out *.app +Tests/GCD +Tests/AutoTest From d8bca8eb3d009f23a697b8207641c328af654e3f Mon Sep 17 00:00:00 2001 From: Micah Date: Sat, 28 Dec 2019 20:08:34 -0600 Subject: [PATCH 03/12] Update CMakeLists.txt Accurately detect if system is Raspberry Pi --- Lib/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/CMakeLists.txt b/Lib/CMakeLists.txt index 1658485..588fbe8 100644 --- a/Lib/CMakeLists.txt +++ b/Lib/CMakeLists.txt @@ -16,9 +16,8 @@ endif() add_library(QPULib "") #Compile differently for the Raspberry Pi -include(CheckIncludeFile) -CHECK_INCLUDE_FILE(/opt/vc/include/bcm_host.h BCMHOST) -if (BCMHOST) #This is a Pi +find_path(HAS_BCMHOST bcm_host.h PATHS /opt/vc/include/) +if (HAS_BCMHOST) #This is a Pi message(STATUS "This is a Pi") #Set precompiler flags add_definitions(-DEMULATION_MODE) From ed533f3debdaa6d7c919dc33015c531de4dc32b8 Mon Sep 17 00:00:00 2001 From: Micah Date: Thu, 2 Jan 2020 22:31:01 -0600 Subject: [PATCH 04/12] Make QPULib.h accessible to outside projects, ignore warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cast from ‘void*’ to ‘uint32_t {aka unsigned int}’ loses precision when compiling on 64 bit systems --- CMakeLists.txt | 94 ++++++++++++++++++++++++++++++++++++++++++++- Lib/CMakeLists.txt | 95 ---------------------------------------------- Tests/Makefile | 2 +- 3 files changed, 93 insertions(+), 98 deletions(-) delete mode 100644 Lib/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index b0189ac..82ac699 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,94 @@ -# Include Source files. -add_subdirectory ("Lib") \ No newline at end of file +#QPULib uses assert statements that throw errors when compiling with g++ on platforms other than the Pi +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_definitions(-fpermissive) +endif() + + + +#file(GLOB_RECURSE QPULIB_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp") +#message(STATUS "QPULib library source files: ${QPULIB_SOURCES}") +#file(GLOB_RECURSE QPULIB_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h" "*.hpp") + + + +add_library(QPULib "") + +#Compile differently for the Raspberry Pi +find_path(HAS_BCMHOST bcm_host.h PATHS /opt/vc/include/) +if (HAS_BCMHOST) #This is a Pi + message(STATUS "This is a Pi") + #Set precompiler flags + add_definitions(-DEMULATION_MODE) + #Compile stuff + target_sources(QPULib + PRIVATE + Lib/Kernel.cpp + Lib/Source/Float.cpp + Lib/Source/Gen.cpp + Lib/Source/Int.cpp + Lib/Source/Interpreter.cpp + Lib/Source/Pretty.cpp + Lib/Source/Stmt.cpp + Lib/Source/Syntax.cpp + Lib/Source/Translate.cpp + Lib/Target/CFG.cpp + Lib/Target/Emulator.cpp + Lib/Target/Encode.cpp + Lib/Target/LiveRangeSplit.cpp + Lib/Target/Liveness.cpp + Lib/Target/LoadStore.cpp + Lib/Target/Pretty.cpp + Lib/Target/ReachingDefs.cpp + Lib/Target/RegAlloc.cpp + Lib/Target/RemoveLabels.cpp + Lib/Target/Satisfy.cpp + Lib/Target/SmallLiteral.cpp + Lib/Target/Subst.cpp + Lib/Target/Syntax.cpp + Lib/VideoCore/Invoke.cpp + Lib/VideoCore/Mailbox.cpp + Lib/VideoCore/VideoCore.cpp + ) + +else() #Not compiling on the Pi + message(STATUS "This is not a Pi") + #Add precompiler definitions + add_definitions(-DEMULATION_MODE) + #Compile stuff + target_sources(QPULib + PRIVATE + Lib/Kernel.cpp + Lib/Source/Float.cpp + Lib/Source/Gen.cpp + Lib/Source/Int.cpp + Lib/Source/Interpreter.cpp + Lib/Source/Pretty.cpp + Lib/Source/Stmt.cpp + Lib/Source/Syntax.cpp + Lib/Source/Translate.cpp + Lib/Target/CFG.cpp + Lib/Target/Emulator.cpp + Lib/Target/Encode.cpp + Lib/Target/LiveRangeSplit.cpp + Lib/Target/Liveness.cpp + Lib/Target/LoadStore.cpp + Lib/Target/Pretty.cpp + Lib/Target/ReachingDefs.cpp + Lib/Target/RegAlloc.cpp + Lib/Target/RemoveLabels.cpp + Lib/Target/Satisfy.cpp + Lib/Target/SmallLiteral.cpp + Lib/Target/Subst.cpp + Lib/Target/Syntax.cpp + ) + +endif() + + + +target_include_directories(QPULib + PUBLIC + Lib/ + ) \ No newline at end of file diff --git a/Lib/CMakeLists.txt b/Lib/CMakeLists.txt deleted file mode 100644 index 588fbe8..0000000 --- a/Lib/CMakeLists.txt +++ /dev/null @@ -1,95 +0,0 @@ - - -#QPULib uses assert statements that throw errors when compiling with g++ on platforms other than the Pi -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - add_definitions(-fpermissive) -endif() - - - -#file(GLOB_RECURSE QPULIB_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp") -#message(STATUS "QPULib library source files: ${QPULIB_SOURCES}") -#file(GLOB_RECURSE QPULIB_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h" "*.hpp") - - - -add_library(QPULib "") - -#Compile differently for the Raspberry Pi -find_path(HAS_BCMHOST bcm_host.h PATHS /opt/vc/include/) -if (HAS_BCMHOST) #This is a Pi - message(STATUS "This is a Pi") - #Set precompiler flags - add_definitions(-DEMULATION_MODE) - #Compile stuff - target_sources(QPULib - PRIVATE - Kernel.cpp - Source/Float.cpp - Source/Gen.cpp - Source/Int.cpp - Source/Interpreter.cpp - Source/Pretty.cpp - Source/Stmt.cpp - Source/Syntax.cpp - Source/Translate.cpp - Target/CFG.cpp - Target/Emulator.cpp - Target/Encode.cpp - Target/LiveRangeSplit.cpp - Target/Liveness.cpp - Target/LoadStore.cpp - Target/Pretty.cpp - Target/ReachingDefs.cpp - Target/RegAlloc.cpp - Target/RemoveLabels.cpp - Target/Satisfy.cpp - Target/SmallLiteral.cpp - Target/Subst.cpp - Target/Syntax.cpp - VideoCore/Invoke.cpp - VideoCore/Mailbox.cpp - VideoCore/VideoCore.cpp - ) -else() #Not compiling on the Pi - message(STATUS "This is not a Pi") - #Add precompiler definitions - add_definitions(-DEMULATION_MODE) - #Compile stuff - target_sources(QPULib - PRIVATE - Kernel.cpp - Source/Float.cpp - Source/Gen.cpp - Source/Int.cpp - Source/Interpreter.cpp - Source/Pretty.cpp - Source/Stmt.cpp - Source/Syntax.cpp - Source/Translate.cpp - Target/CFG.cpp - Target/Emulator.cpp - Target/Encode.cpp - Target/LiveRangeSplit.cpp - Target/Liveness.cpp - Target/LoadStore.cpp - Target/Pretty.cpp - Target/ReachingDefs.cpp - Target/RegAlloc.cpp - Target/RemoveLabels.cpp - Target/Satisfy.cpp - Target/SmallLiteral.cpp - Target/Subst.cpp - Target/Syntax.cpp - ) -endif() - -target_include_directories(QPULib - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/Source - ${CMAKE_CURRENT_LIST_DIR}/Common - ${CMAKE_CURRENT_LIST_DIR}/Target - ${CMAKE_CURRENT_LIST_DIR}/VideoCore - ${CMAKE_CURRENT_LIST_DIR} - ${CMAKE_CURRENT_BINARY_DIR} - ) \ No newline at end of file diff --git a/Tests/Makefile b/Tests/Makefile index a23b0c8..b7b5323 100644 --- a/Tests/Makefile +++ b/Tests/Makefile @@ -3,7 +3,7 @@ ROOT = ../Lib # Compiler and default flags CXX = g++ -CXX_FLAGS = -Wconversion -std=c++0x -I $(ROOT) +CXX_FLAGS = -fpermissive -Wconversion -std=c++0x -I $(ROOT) # Object directory OBJ_DIR = obj From be1c2c47ff64c6200caf3a70485ab6bf17584f06 Mon Sep 17 00:00:00 2001 From: Micah Date: Sat, 4 Jan 2020 22:36:57 -0600 Subject: [PATCH 05/12] Encapsulate library compilation in the Lib folder --- CMakeLists.txt | 95 +--------------------------------------------- Lib/CMakeLists.txt | 84 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 94 deletions(-) create mode 100644 Lib/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 82ac699..0b76319 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,94 +1 @@ - - -#QPULib uses assert statements that throw errors when compiling with g++ on platforms other than the Pi -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - add_definitions(-fpermissive) -endif() - - - -#file(GLOB_RECURSE QPULIB_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp") -#message(STATUS "QPULib library source files: ${QPULIB_SOURCES}") -#file(GLOB_RECURSE QPULIB_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h" "*.hpp") - - - -add_library(QPULib "") - -#Compile differently for the Raspberry Pi -find_path(HAS_BCMHOST bcm_host.h PATHS /opt/vc/include/) -if (HAS_BCMHOST) #This is a Pi - message(STATUS "This is a Pi") - #Set precompiler flags - add_definitions(-DEMULATION_MODE) - #Compile stuff - target_sources(QPULib - PRIVATE - Lib/Kernel.cpp - Lib/Source/Float.cpp - Lib/Source/Gen.cpp - Lib/Source/Int.cpp - Lib/Source/Interpreter.cpp - Lib/Source/Pretty.cpp - Lib/Source/Stmt.cpp - Lib/Source/Syntax.cpp - Lib/Source/Translate.cpp - Lib/Target/CFG.cpp - Lib/Target/Emulator.cpp - Lib/Target/Encode.cpp - Lib/Target/LiveRangeSplit.cpp - Lib/Target/Liveness.cpp - Lib/Target/LoadStore.cpp - Lib/Target/Pretty.cpp - Lib/Target/ReachingDefs.cpp - Lib/Target/RegAlloc.cpp - Lib/Target/RemoveLabels.cpp - Lib/Target/Satisfy.cpp - Lib/Target/SmallLiteral.cpp - Lib/Target/Subst.cpp - Lib/Target/Syntax.cpp - Lib/VideoCore/Invoke.cpp - Lib/VideoCore/Mailbox.cpp - Lib/VideoCore/VideoCore.cpp - ) - -else() #Not compiling on the Pi - message(STATUS "This is not a Pi") - #Add precompiler definitions - add_definitions(-DEMULATION_MODE) - #Compile stuff - target_sources(QPULib - PRIVATE - Lib/Kernel.cpp - Lib/Source/Float.cpp - Lib/Source/Gen.cpp - Lib/Source/Int.cpp - Lib/Source/Interpreter.cpp - Lib/Source/Pretty.cpp - Lib/Source/Stmt.cpp - Lib/Source/Syntax.cpp - Lib/Source/Translate.cpp - Lib/Target/CFG.cpp - Lib/Target/Emulator.cpp - Lib/Target/Encode.cpp - Lib/Target/LiveRangeSplit.cpp - Lib/Target/Liveness.cpp - Lib/Target/LoadStore.cpp - Lib/Target/Pretty.cpp - Lib/Target/ReachingDefs.cpp - Lib/Target/RegAlloc.cpp - Lib/Target/RemoveLabels.cpp - Lib/Target/Satisfy.cpp - Lib/Target/SmallLiteral.cpp - Lib/Target/Subst.cpp - Lib/Target/Syntax.cpp - ) - -endif() - - - -target_include_directories(QPULib - PUBLIC - Lib/ - ) \ No newline at end of file +add_subdirectory("Lib") \ No newline at end of file diff --git a/Lib/CMakeLists.txt b/Lib/CMakeLists.txt new file mode 100644 index 0000000..ef828c7 --- /dev/null +++ b/Lib/CMakeLists.txt @@ -0,0 +1,84 @@ +#QPULib uses assert statements that throw errors when compiling with g++ on platforms other than the Pi +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_definitions(-fpermissive) +endif() + + + +#file(GLOB_RECURSE QPULIB_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp") +#message(STATUS "QPULib library source files: ${QPULIB_SOURCES}") +#file(GLOB_RECURSE QPULIB_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h" "*.hpp") + +include_directories("${CMAKE_CURRENT_SOURCE_DIR}") + + +SET(QPULIB_SOURCES +#Source files +Kernel.cpp +Source/Float.cpp +Source/Gen.cpp +Source/Int.cpp +Source/Interpreter.cpp +Source/Pretty.cpp +Source/Stmt.cpp +Source/Syntax.cpp +Source/Translate.cpp +Target/CFG.cpp +Target/Emulator.cpp +Target/Encode.cpp +Target/Liveness.cpp +Target/LiveRangeSplit.cpp +Target/LoadStore.cpp +Target/Pretty.cpp +Target/ReachingDefs.cpp +Target/RegAlloc.cpp +Target/RemoveLabels.cpp +Target/Satisfy.cpp +Target/SmallLiteral.cpp +Target/Subst.cpp +Target/Syntax.cpp +VideoCore/Invoke.cpp +VideoCore/Mailbox.cpp +VideoCore/VideoCore.cpp +#Header files +Common/Heap.h +Common/Seq.h +Common/Stack.h +Kernel.h +Params.h +QPULib.h +Source/Cond.h +Source/Float.h +Source/Gen.h +Source/Int.h +Source/Interpreter.h +Source/Pretty.h +Source/Ptr.h +Source/Stmt.h +Source/StmtExtra.h +Source/Syntax.h +Source/Translate.h +Target/CFG.h +Target/Emulator.h +Target/Encode.h +Target/Liveness.h +Target/LiveRangeSplit.h +Target/LoadStore.h +Target/Pretty.h +Target/ReachingDefs.h +Target/RegAlloc.h +Target/RemoveLabels.h +Target/Satisfy.h +Target/SmallLiteral.h +Target/Subst.h +Target/Syntax.h +VideoCore/Invoke.h +VideoCore/Mailbox.h +VideoCore/SharedArray.h +VideoCore/VideoCore.h +) + +add_library(QPULib +STATIC +${QPULIB_SOURCES} +) From b48ef2571050a3791e6ec476a5a1f1ba91deb8cc Mon Sep 17 00:00:00 2001 From: Micah Date: Sun, 5 Jan 2020 10:41:34 -0600 Subject: [PATCH 06/12] Only compile Invoke, VideoCore, Mailbox if in QPU Mode These files are only needed for using the Pi's QPU and are unnecessary for emulation. Furthermore, they require Linux-specific libraries (which is why QPULib can't be emulated on WIndows) Now that they aren't compiled on Windows, QPULib can be compiled in emulation mode on Windows as well --- Lib/Kernel.h | 2 ++ Lib/VideoCore/SharedArray.h | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Lib/Kernel.h b/Lib/Kernel.h index 72bf96b..f16e171 100644 --- a/Lib/Kernel.h +++ b/Lib/Kernel.h @@ -5,8 +5,10 @@ #include "Target/Emulator.h" #include "Target/Encode.h" #include "VideoCore/SharedArray.h" +#ifdef QPU_MODE #include "VideoCore/Invoke.h" #include "VideoCore/VideoCore.h" +#endif // ============================================================================ // Modes of operation diff --git a/Lib/VideoCore/SharedArray.h b/Lib/VideoCore/SharedArray.h index b1ee0eb..824d835 100644 --- a/Lib/VideoCore/SharedArray.h +++ b/Lib/VideoCore/SharedArray.h @@ -4,8 +4,11 @@ #include #include #include -#include "VideoCore/Mailbox.h" -#include "VideoCore/VideoCore.h" + +#ifdef QPU_MODE + #include "VideoCore/Mailbox.h" + #include "VideoCore/VideoCore.h" +#endif #ifdef EMULATION_MODE From dedcaf96b5b5d50b0cb5992ba09c4f0865fb8912 Mon Sep 17 00:00:00 2001 From: Micah Date: Sun, 5 Jan 2020 10:44:05 -0600 Subject: [PATCH 07/12] Update CMakeLists.txt Don't compile VideoCore, Mailbox, and Invoke when in emulation mode, so QPULib can be compiled by Windows machines --- Lib/CMakeLists.txt | 145 +++++++++++++++++++++++++-------------------- 1 file changed, 82 insertions(+), 63 deletions(-) diff --git a/Lib/CMakeLists.txt b/Lib/CMakeLists.txt index ef828c7..0e8d96b 100644 --- a/Lib/CMakeLists.txt +++ b/Lib/CMakeLists.txt @@ -1,3 +1,5 @@ +message(STATUS "Creating Makefile for QPULib") + #QPULib uses assert statements that throw errors when compiling with g++ on platforms other than the Pi if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") add_definitions(-fpermissive) @@ -12,72 +14,89 @@ endif() include_directories("${CMAKE_CURRENT_SOURCE_DIR}") +# Compile Invoke, Mailbox, VideoCore if not emulating +# Check if this is a Pi +# Compile differently for the Raspberry Pi +find_path(HAS_BCMHOST bcm_host.h PATHS /opt/vc/include/) +if (HAS_BCMHOST) #This is a Pi + add_definitions(-DQPU_MODE) + SET(QPULIB_SOURCES + ${QPULIB_SOURCES} + VideoCore/Invoke.cpp + VideoCore/Mailbox.cpp + VideoCore/VideoCore.cpp + VideoCore/Invoke.h + VideoCore/Mailbox.h + VideoCore/VideoCore.h + ) + +else() #Not compiling on the Pi + add_definitions(-DEMULATION_MODE) + +endif() + SET(QPULIB_SOURCES -#Source files -Kernel.cpp -Source/Float.cpp -Source/Gen.cpp -Source/Int.cpp -Source/Interpreter.cpp -Source/Pretty.cpp -Source/Stmt.cpp -Source/Syntax.cpp -Source/Translate.cpp -Target/CFG.cpp -Target/Emulator.cpp -Target/Encode.cpp -Target/Liveness.cpp -Target/LiveRangeSplit.cpp -Target/LoadStore.cpp -Target/Pretty.cpp -Target/ReachingDefs.cpp -Target/RegAlloc.cpp -Target/RemoveLabels.cpp -Target/Satisfy.cpp -Target/SmallLiteral.cpp -Target/Subst.cpp -Target/Syntax.cpp -VideoCore/Invoke.cpp -VideoCore/Mailbox.cpp -VideoCore/VideoCore.cpp -#Header files -Common/Heap.h -Common/Seq.h -Common/Stack.h -Kernel.h -Params.h -QPULib.h -Source/Cond.h -Source/Float.h -Source/Gen.h -Source/Int.h -Source/Interpreter.h -Source/Pretty.h -Source/Ptr.h -Source/Stmt.h -Source/StmtExtra.h -Source/Syntax.h -Source/Translate.h -Target/CFG.h -Target/Emulator.h -Target/Encode.h -Target/Liveness.h -Target/LiveRangeSplit.h -Target/LoadStore.h -Target/Pretty.h -Target/ReachingDefs.h -Target/RegAlloc.h -Target/RemoveLabels.h -Target/Satisfy.h -Target/SmallLiteral.h -Target/Subst.h -Target/Syntax.h -VideoCore/Invoke.h -VideoCore/Mailbox.h -VideoCore/SharedArray.h -VideoCore/VideoCore.h + ${QPULIB_SOURCES} + #Source files + Kernel.cpp + Source/Float.cpp + Source/Gen.cpp + Source/Int.cpp + Source/Interpreter.cpp + Source/Pretty.cpp + Source/Stmt.cpp + Source/Syntax.cpp + Source/Translate.cpp + Target/CFG.cpp + Target/Emulator.cpp + Target/Encode.cpp + Target/Liveness.cpp + Target/LiveRangeSplit.cpp + Target/LoadStore.cpp + Target/Pretty.cpp + Target/ReachingDefs.cpp + Target/RegAlloc.cpp + Target/RemoveLabels.cpp + Target/Satisfy.cpp + Target/SmallLiteral.cpp + Target/Subst.cpp + Target/Syntax.cpp + #Header files + Common/Heap.h + Common/Seq.h + Common/Stack.h + Kernel.h + Params.h + QPULib.h + Source/Cond.h + Source/Float.h + Source/Gen.h + Source/Int.h + Source/Interpreter.h + Source/Pretty.h + Source/Ptr.h + Source/Stmt.h + Source/StmtExtra.h + Source/Syntax.h + Source/Translate.h + Target/CFG.h + Target/Emulator.h + Target/Encode.h + Target/Liveness.h + Target/LiveRangeSplit.h + Target/LoadStore.h + Target/Pretty.h + Target/ReachingDefs.h + Target/RegAlloc.h + Target/RemoveLabels.h + Target/Satisfy.h + Target/SmallLiteral.h + Target/Subst.h + Target/Syntax.h + VideoCore/SharedArray.h ) + add_library(QPULib STATIC ${QPULIB_SOURCES} From a00be928a0f33b9cb973ae13f934ea5d5a449905 Mon Sep 17 00:00:00 2001 From: Micah Date: Sun, 5 Jan 2020 10:44:17 -0600 Subject: [PATCH 08/12] Update CMakeLists.txt --- Lib/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lib/CMakeLists.txt b/Lib/CMakeLists.txt index 0e8d96b..0f8234b 100644 --- a/Lib/CMakeLists.txt +++ b/Lib/CMakeLists.txt @@ -5,8 +5,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") add_definitions(-fpermissive) endif() - - #file(GLOB_RECURSE QPULIB_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp") #message(STATUS "QPULib library source files: ${QPULIB_SOURCES}") #file(GLOB_RECURSE QPULIB_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h" "*.hpp") From 07a2dfe5d73829c4d706fc6ea417c0c48d82fb09 Mon Sep 17 00:00:00 2001 From: Micah Date: Sun, 5 Jan 2020 11:24:53 -0600 Subject: [PATCH 09/12] Documentation --- README.md | 3 +- README_CMake.md | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 README_CMake.md diff --git a/README.md b/README.md index 8f06b75..f0a0bc5 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ Pi](https://www.raspberrypi.org/)'s *Quad Processing Units* (QPUs). It is implemented as a C++ library that runs on the Pi's ARM CPU, generating and offloading programs to the QPUs at runtime. This page introduces and documents QPULib. For build instructions, see the -[Getting Started Guide](Doc/GettingStarted.md). +[Getting Started Guide](Doc/GettingStarted.md) and the +[CMake build instructions](README_CMake.md). ## Contents diff --git a/README_CMake.md b/README_CMake.md new file mode 100644 index 0000000..0464136 --- /dev/null +++ b/README_CMake.md @@ -0,0 +1,73 @@ +# Bulding with CMake +## Introduction + +This document explains how to make a project with QPULib and CMake. +An example CMake project has been set up +[here](https://github.com/m516/PiGPGPU) +as reference and to be used as a template for new projects. + +The general file structure for a C++ project with QPULib is like so: +``` +lib/ + QPULib/ + QPULib source files + +src/ + + CMakeLists.txt +CMakeLists.txt +``` + +If prepared properly, your project can be easily built on Windows, +Mac OS, and Linux platforms, even though QPULib targets Raspberry Pi +hardware. The example project has been tested with Windows 10, +Raspbian Buster on a Pi 0W, and Ubuntu with minimal configuration on +all platforms. + +## Writing CMake Scripts +CMake scripts are a pain in the butt to set up, but they make the build +process easy. CMake reads text files with the name `CMakeLists.txt` +and generates Makefiles. The Makefiles are interpreted by Make to +build your project with the C++ compiler on your OS. + +The `CMakeLists.txt` file in the root directory should be used to +set up the project, store the list of libraries, and start the build +processes for all your subprojects. +```CMake +# CMakeList.txt : Top-level CMake project file, do global configuration +# and include sub-projects here. +# +cmake_minimum_required (VERSION 3.8) + +project (PiGPGPU) + +# Include libraries +add_subdirectory("lib") + + +#Compile differently for the Raspberry Pi +find_path(HAS_BCMHOST bcm_host.h PATHS /opt/vc/include/) +if (HAS_BCMHOST) #This is a Pi + message(STATUS "This is a Pi") + message(STATUS "Targeting VideoCore IV GPU") + #Set precompiler flags + add_definitions(-DQPU_MODE) + +else() #Not compiling on the Pi + message(STATUS "This is not a Pi") + message(STATUS "Emulating Pi's GPU") + #Add precompiler definitions + add_definitions(-DEMULATION_MODE) +endif() + +#Include QPULib +add_subdirectory("lib/QPULib") +include_directories("${PROJECT_SOURCE_DIR}/lib/QPULib/Lib") + +add_subdirectory("src") +``` + +## Conclusion +If you have any suggestions or issues, I'd love to hear them and help! +The best way to contact me is the issues tab of the Github repository. +Good luck and happy hacking! From ff3232955a40fede66a167a4e46016edc90753a4 Mon Sep 17 00:00:00 2001 From: Micah Date: Fri, 17 Jan 2020 00:49:20 -0600 Subject: [PATCH 10/12] Change End to EndBlock the End macro conflicts with SFML's Keyboard::End --- Lib/Source/Stmt.cpp | 4 ++-- Lib/Source/Stmt.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/Source/Stmt.cpp b/Lib/Source/Stmt.cpp index 16715c4..04390dd 100644 --- a/Lib/Source/Stmt.cpp +++ b/Lib/Source/Stmt.cpp @@ -217,9 +217,9 @@ void kernelFinish() Int n = numQPUs()-1; For (Int i = 0, i < n, i++) semaDec(15); - End + EndBlock hostIRQ(); Else semaInc(15); - End + EndBlock } diff --git a/Lib/Source/Stmt.h b/Lib/Source/Stmt.h index 496ac17..9cfde1b 100644 --- a/Lib/Source/Stmt.h +++ b/Lib/Source/Stmt.h @@ -12,7 +12,7 @@ #define If(c) If_(c); { #define Else } Else_(); { -#define End } End_(); +#define EndBlock } End_(); #define While(c) While_(c); { #define Where(b) Where_(b); { #define For(init, cond, inc) \ From 82c336579c8713acb4a9da99b941cb5f27243556 Mon Sep 17 00:00:00 2001 From: Micah Date: Fri, 17 Jan 2020 00:53:00 -0600 Subject: [PATCH 11/12] Update README.md Change End to EndBlock, just as what was done in the actual source code --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f0a0bc5..4c9fe2e 100644 --- a/README.md +++ b/README.md @@ -130,11 +130,11 @@ void gcd(Ptr p, Ptr q, Ptr r) While (any(a != b)) Where (a > b) a = a-b; - End + EndBlock Where (a < b) b = b-a; - End - End + EndBlock + EndBlock *r = a; } ``` @@ -156,7 +156,7 @@ Even this simple example introduces a number of concepts: * the condition `any(a != b)` is true when *any* of the booleans in the vector `a != b` are true; - * the statement `Where (a > b) a = a-b; End` is a conditional assigment: + * the statement `Where (a > b) a = a-b; EndBlock` is a conditional assigment: only elements in vector `a` for which `a > b` holds will be modified. @@ -264,12 +264,12 @@ void gcd(Ptr p, Ptr q, Ptr r) for (int i = 0; i < 32; i++) { Where (a > b) a = a-b; - End + EndBlock Where (a < b) b = b-a; - End + EndBlock } - End + EndBlock *r = a; } ``` @@ -329,7 +329,7 @@ void rot3D(Int n, Float cosTheta, Float sinTheta, Ptr x, Ptr y) Float yOld = y[i]; x[i] = xOld * cosTheta - yOld * sinTheta; y[i] = yOld * cosTheta + xOld * sinTheta; - End + EndBlock } ``` @@ -400,7 +400,7 @@ void rot3D(Int n, Float cosTheta, Float sinTheta, Ptr x, Ptr y) store(xOld * cosTheta - yOld * sinTheta, p); store(yOld * cosTheta + xOld * sinTheta, q); p = p+16; q = q+16; - End + EndBlock // Discard pre-fetched vectors from final iteration receive(xOld); receive(yOld); @@ -444,7 +444,7 @@ void rot3D(Int n, Float cosTheta, Float sinTheta, Ptr x, Ptr y) store(xOld * cosTheta - yOld * sinTheta, p); store(yOld * cosTheta + xOld * sinTheta, q); p = p+inc; q = q+inc; - End + EndBlock // Discard pre-fetched vectors from final iteration receive(xOld); receive(yOld); @@ -588,7 +588,7 @@ class Cursor { Float nextRot = rotate(next, 15); Where (index() == 15) result = nextRot; - End + EndBlock } // Shift the current vector right one element @@ -597,7 +597,7 @@ class Cursor { Float prevRot = rotate(prev, 1); Where (index() == 0) result = prevRot; - End + EndBlock } }; ``` @@ -647,14 +647,14 @@ void step(Ptr grid, Ptr gridOut, Int pitch, Int width, Int height) store(row[1].current - K * (row[1].current - sum * 0.125), p); p = p + 16; - End + EndBlock // Cursors are finished for this row for (int i = 0; i < 3; i++) row[i].finish(); // Move to the next input rows grid = grid + pitch*numQPUs(); - End + EndBlock } ``` From e76fa94adccb1804a9c9a4ba6acefec21a9da77e Mon Sep 17 00:00:00 2001 From: Micah Date: Wed, 17 Jun 2020 03:28:24 -0500 Subject: [PATCH 12/12] Update CMakeLists.txt --- Lib/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/CMakeLists.txt b/Lib/CMakeLists.txt index 0f8234b..17ebeb6 100644 --- a/Lib/CMakeLists.txt +++ b/Lib/CMakeLists.txt @@ -18,6 +18,8 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}") find_path(HAS_BCMHOST bcm_host.h PATHS /opt/vc/include/) if (HAS_BCMHOST) #This is a Pi add_definitions(-DQPU_MODE) + add_definitions(-fpermissive) + add_definitions(-std=c++0x) SET(QPULIB_SOURCES ${QPULIB_SOURCES} VideoCore/Invoke.cpp