Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
39 changes: 39 additions & 0 deletions Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
49 changes: 25 additions & 24 deletions Lib/Kernel.h
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -10,39 +12,38 @@
#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'.

// 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
Expand Down Expand Up @@ -174,7 +175,7 @@ template <typename... ts> struct Kernel {
int numQPUs;

// Memory region for QPU code and parameters
#ifdef QPU_MODE
#ifdef QPULIB_QPU_MODE
SharedArray<uint32_t>* qpuCodeMem;
int qpuCodeMemOffset;
#endif
Expand Down Expand Up @@ -209,8 +210,8 @@ template <typename... ts> 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
Expand All @@ -219,7 +220,7 @@ template <typename... ts> struct Kernel {
// Remember the number of variables used
numVars = getFreshVarCount();

#ifdef QPU_MODE
#ifdef QPULIB_QPU_MODE
enableQPUs();

// Allocate code mem
Expand All @@ -242,7 +243,7 @@ template <typename... ts> struct Kernel {
#endif
}

#ifdef EMULATION_MODE
#ifdef QPULIB_EMULATION_MODE
template <typename... us> void emu(us... args) {
// Pass params, checking arguments types us against parameter types ts
uniforms.clear();
Expand All @@ -259,7 +260,7 @@ template <typename... ts> struct Kernel {
#endif

// Invoke the interpreter
#ifdef EMULATION_MODE
#ifdef QPULIB_EMULATION_MODE
template <typename... us> void interpret(us... args) {
// Pass params, checking arguments types us against parameter types ts
uniforms.clear();
Expand All @@ -276,7 +277,7 @@ template <typename... ts> struct Kernel {
#endif

// Invoke kernel on physical QPU hardware
#ifdef QPU_MODE
#ifdef QPULIB_QPU_MODE
template <typename... us> void qpu(us... args) {
// Pass params, checking arguments types us against parameter types ts
uniforms.clear();
Expand All @@ -289,10 +290,10 @@ template <typename... ts> struct Kernel {

// Invoke the kernel
template <typename... us> 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
Expand All @@ -310,7 +311,7 @@ template <typename... ts> struct Kernel {

// Deconstructor
~Kernel() {
#ifdef QPU_MODE
#ifdef QPULIB_QPU_MODE
delete qpuCodeMem;
disableQPUs();
#endif
Expand Down
1 change: 1 addition & 0 deletions Lib/QPULib.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions Lib/Source/Cond.h
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
2 changes: 1 addition & 1 deletion Lib/Source/Float.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define _QPULIB_SOURCE_FLOAT_H_

#include <assert.h>
#include "Source/Syntax.h"
#include "../Source/Syntax.h"

namespace QPULib {

Expand Down
4 changes: 2 additions & 2 deletions Lib/Source/Gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
4 changes: 2 additions & 2 deletions Lib/Source/Int.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#define _QPULIB_SOURCE_INT_H_

#include <assert.h>
#include "Source/Syntax.h"
#include "Source/Float.h"
#include "../Source/Syntax.h"
#include "../Source/Float.h"

namespace QPULib {

Expand Down
6 changes: 3 additions & 3 deletions Lib/Source/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#define _QPULIB_INTERPRETER_H_

#include <stdint.h>
#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 {

Expand Down
2 changes: 1 addition & 1 deletion Lib/Source/Pretty.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _QPULIB_SOURCE_PRETTY_H_
#define _QPULIB_SOURCE_PRETTY_H_

#include "Source/Syntax.h"
#include "../Source/Syntax.h"

namespace QPULib {

Expand Down
2 changes: 1 addition & 1 deletion Lib/Source/Ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define _QPULIB_SOURCE_PTR_H_

#include <assert.h>
#include "Source/Syntax.h"
#include "../Source/Syntax.h"

namespace QPULib {

Expand Down
8 changes: 4 additions & 4 deletions Lib/Source/Stmt.h
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
4 changes: 2 additions & 2 deletions Lib/Source/Syntax.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
6 changes: 3 additions & 3 deletions Lib/Source/Translate.h
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Loading