Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zynq Plugin #112

Open
wants to merge 2 commits into
base: embb111_fpga_plugin
Choose a base branch
from
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
43 changes: 43 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ option(WARNINGS_ARE_ERRORS "Specify whether warnings should be treated as errors
option(USE_AUTOMATIC_INITIALIZATION "Specify whether the MTAPI C++ interface, algorithms and dataflow should automatically intialize the MTAPI node if no explicit initialization is present" ON)
option(BUILD_OPENCL_PLUGIN "Specify whether the MTAPI OpenCL plugin should be built" OFF)
option(BUILD_CUDA_PLUGIN "Specify whether the MTAPI CUDA plugin should be built" OFF)
option(BUILD_PL_PLUGIN "Specify whether the MTAPI PL plugin should be built" ON)
option(BUILD_ZYNQ_PLUGIN "Specify whether the MTAPI Zynq plugin should be built" ON)
option(THREADING_ANALYSIS_MODE "Replaces lock-free synchronization constructs by mutex-based implementations to support threading analysis tools" OFF)
option(BUILD_SHARED_LIBS "Specify whether shared libs should be built" OFF)

Expand Down Expand Up @@ -174,6 +176,38 @@ if(BUILD_OPENCL_PLUGIN STREQUAL ON)
list(APPEND EXPECTED_EMBB_TEST_EXECUTABLES "embb_mtapi_opencl_c_test")
endif()

if (BUILD_PL_PLUGIN STREQUAL ON)
message("-- Building PL plugin enabled")
else()
message("-- Building PL plugin disabled (default)")
endif()
message(" (set with command line option -DBUILD_PL_PLUGIN=ON/OFF)")

if(BUILD_PL_PLUGIN STREQUAL ON)
list(APPEND EXPECTED_EMBB_TEST_EXECUTABLES "embb_mtapi_pl_c_test")
endif()

if (BUILD_PL_2_PLUGIN STREQUAL ON)
message("-- Building PL 2 plugin enabled")
else()
message("-- Building PL 2 plugin disabled (default)")
endif()
message(" (set with command line option -DBUILD_PL_2_PLUGIN=ON/OFF)")
if(BUILD_PL_2_PLUGIN STREQUAL ON)
list(APPEND EXPECTED_EMBB_TEST_EXECUTABLES "embb_mtapi_pl_2_c_test")
endif()

if (BUILD_ZYNQ_PLUGIN STREQUAL ON)
message("-- Building Zynq plugin enabled")
else()
message("-- Building Zynq plugin disabled (default)")
endif()
message(" (set with command line option -DBUILD_ZYNQ_PLUGIN=ON/OFF)")

if(BUILD_ZYNQ_PLUGIN STREQUAL ON)
list(APPEND EXPECTED_EMBB_TEST_EXECUTABLES "embb_mtapi_zynq_c_test")
endif()

if (BUILD_CUDA_PLUGIN STREQUAL ON)
message("-- Building CUDA plugin enabled")
else()
Expand Down Expand Up @@ -227,6 +261,15 @@ if(BUILD_CUDA_PLUGIN STREQUAL ON)
add_subdirectory(mtapi_plugins_c/mtapi_cuda_c)
endif()
endif()
if(BUILD_PL_PLUGIN STREQUAL ON)
add_subdirectory(mtapi_plugins_c/mtapi_pl_c)
endif()
if(BUILD_PL_2_PLUGIN STREQUAL ON)
add_subdirectory(mtapi_plugins_c/mtapi_pl_2_c)
endif()
if(BUILD_ZYNQ_PLUGIN STREQUAL ON)
add_subdirectory(mtapi_plugins_c/mtapi_zynq_c)
endif()
add_subdirectory(mtapi_cpp)
add_subdirectory(containers_cpp)
add_subdirectory(algorithms_cpp)
Expand Down
58 changes: 58 additions & 0 deletions mtapi_plugins_c/mtapi_zynq_c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
project (project_embb_mtapi_zynq_c)

file(GLOB_RECURSE EMBB_MTAPI_ZYNQ_C_SOURCES "src/*.c" "src/*.h")
file(GLOB_RECURSE EMBB_MTAPI_ZYNQ_C_HEADERS "include/*.h")

file(GLOB_RECURSE EMBB_MTAPI_ZYNQ_TEST_SOURCES "test/*.cc" "test/*.h")

IF(MSVC8 OR MSVC9 OR MSVC10 OR MSVC11)
FOREACH(src_tmp ${EMBB_MTAPI_ZYNQ_TEST_SOURCES})
SET_PROPERTY(SOURCE ${src_tmp} PROPERTY LANGUAGE CXX)
ENDFOREACH(src_tmp)
FOREACH(src_tmp ${EMBB_MTAPI_ZYNQ_C_SOURCES})
SET_PROPERTY(SOURCE ${src_tmp} PROPERTY LANGUAGE CXX)
ENDFOREACH(src_tmp)
ENDIF()

IF(CMAKE_COMPILER_IS_GNUCC)
set (EMBB_MTAPI_ZYNQ_C_LIBS dl)
ENDIF()

# Execute the GroupSources macro
include(${CMAKE_SOURCE_DIR}/CMakeCommon/GroupSourcesMSVC.cmake)
GroupSourcesMSVC(include)
GroupSourcesMSVC(src)
GroupSourcesMSVC(test)

set (EMBB_MTAPI_ZYNQ_INCLUDE_DIRS "include" "src" "test")
include_directories(${EMBB_MTAPI_ZYNQ_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/../../base_c/include
${CMAKE_CURRENT_BINARY_DIR}/../../base_c/include
${CMAKE_CURRENT_SOURCE_DIR}/../../mtapi_c/include
${CMAKE_CURRENT_SOURCE_DIR}/../../mtapi_c/src
)

add_library(embb_mtapi_zynq_c ${EMBB_MTAPI_ZYNQ_C_SOURCES} ${EMBB_MTAPI_ZYNQ_C_HEADERS})
target_link_libraries(embb_mtapi_zynq_c embb_mtapi_c embb_base_c )
if (BUILD_SHARED_LIBS STREQUAL ON)
if (MSVC)
set_target_properties(embb_mtapi_zynq_c PROPERTIES LINK_FLAGS "/DEF:\"${CMAKE_CURRENT_SOURCE_DIR}/src/exports.def\"")
CopyBin(BIN embb_mtapi_zynq_c DEST ${local_install_dir})
endif()
endif()

if (BUILD_TESTS STREQUAL ON)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../partest/include)
add_executable (embb_mtapi_zynq_c_test ${EMBB_MTAPI_ZYNQ_TEST_SOURCES})
target_link_libraries(embb_mtapi_zynq_c_test embb_mtapi_zynq_c embb_mtapi_c partest embb_base_c ${compiler_libs} ${EMBB_MTAPI_ZYNQ_C_LIBS})
CopyBin(BIN embb_mtapi_zynq_c_test DEST ${local_install_dir})
endif()

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION include FILES_MATCHING PATTERN "*.h")
install(TARGETS embb_mtapi_zynq_c EXPORT EMBB-Targets DESTINATION lib)
if (MSVC)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Debug/embb_mtapi_zynq_c.pdb
DESTINATION lib
CONFIGURATIONS Debug)
endif()
192 changes: 192 additions & 0 deletions mtapi_plugins_c/mtapi_zynq_c/include/embb/mtapi/c/mtapi_zynq.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*
* Copyright (c) 2014-2017, Siemens AG. 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
*/

#ifndef EMBB_MTAPI_C_MTAPI_ZYNQ_H_
#define EMBB_MTAPI_C_MTAPI_ZYNQ_H_


#include <embb/mtapi/c/mtapi_ext.h>


#ifdef __cplusplus
extern "C" {
#endif

/**
* \defgroup C_MTAPI_ZYNQ MTAPI ZYNQ Plugin
*
* \ingroup C_MTAPI_EXT
*
* Provides functionality to execute tasks on Zynq devices.
*/


/**
* Initializes the MTAPI Zynq environment on a previously initialized MTAPI
* node.
*
* It must be called on all nodes using the MTAPI Zynq plugin.
*
* Application software using MTAPI Zynq must call
* mtapi_zynq_plugin_initialize() once per node. It is an error to call
* mtapi_zynq_plugin_initialize() multiple times
* from a given node, unless mtapi_zynq_plugin_finalize() is called in
* between.
*
* On success, \c *status is set to \c MTAPI_SUCCESS. On error, \c *status is
* set to the appropriate error defined below.
* Error code | Description
* --------------------------- | ----------------------------------------------
* \c MTAPI_ERR_UNKNOWN | MTAPI Zynq couldn't be initialized.
*
* \see mtapi_zynq_plugin_finalize()
*
* \notthreadsafe
* \ingroup C_MTAPI_ZYNQ
*/
void mtapi_zynq_plugin_initialize(
MTAPI_IN char* uio_name, /**< [out] UIO device tree name */
MTAPI_OUT mtapi_status_t* status /**< [out] Pointer to error code,
may be \c MTAPI_NULL */
);

/**
* Finalizes the MTAPI Zynq environment on the local MTAPI node.
*
* It has to be called by each node using MTAPI Zynq. It is an error to call
* mtapi_zynq_plugin_finalize() without first calling
* mtapi_zynq_plugin_initialize(). An MTAPI node can call
* mtapi_zynq_plugin_finalize() once for each call to
* mtapi_zynq_plugin_initialize(), but it is an error to call
* mtapi_zynq_plugin_finalize() multiple times from a given node
* unless mtapi_zynq_plugin_initialize() has been called prior to each
* mtapi_zynq_plugin_finalize() call.
*
* All Zynq tasks that have not completed and that have been started on the
* node where mtapi_zynq_plugin_finalize() is called will be canceled
* (see mtapi_task_cancel()). mtapi_zynq_plugin_finalize() blocks until all
* tasks that have been started on the same node return. Tasks that execute
* actions on the node where mtapi_zynq_plugin_finalize() is called, also
* block finalization of the MTAPI Zynq system on that node.
*
* On success, \c *status is set to \c MTAPI_SUCCESS. On error, \c *status is
* set to the appropriate error defined below.
* Error code | Description
* ----------------------------- | --------------------------------------------
* \c MTAPI_ERR_UNKNOWN | MTAPI Zynq couldn't be finalized.
*
* \see mtapi_zynq_plugin_initialize(), mtapi_task_cancel()
*
* \notthreadsafe
* \ingroup C_MTAPI_ZYNQ
*/
void mtapi_zynq_plugin_finalize(
MTAPI_OUT mtapi_status_t* status /**< [out] Pointer to error code,
may be \c MTAPI_NULL */
);

/**
* This function creates a ZYNQ action.
*
* It is called on the node where the user wants to execute an action on a
* Zynq device. A Zynq action contains a reference to a local job and the physical
* address of an accelerator in the programmable logic.
* After a Zynq action is created, it is referenced by the application using
* a node-local handle of type \c mtapi_action_hndl_t, or indirectly through a
* node-local job handle of type \c mtapi_job_hndl_t. A Zynq action's
* life-cycle begins with mtapi_zynq_action_create(), and ends when
* mtapi_action_delete() or mtapi_finalize() is called.
*
* To create an action, the application must supply the domain-wide job ID of
* the job associated with the action. Job IDs must be predefined in the
* application and runtime, of type \c mtapi_job_id_t, which is an
* implementation-defined type. The job ID is unique in the sense that it is
* unique for the job implemented by the action. However several actions may
* implement the same job for load balancing purposes.
*
* If \c node_local_data_size is not zero, \c node_local_data specifies the
* start of node local data shared by kernel functions executed on the same
* node. \c node_local_data_size can be used by the runtime for cache coherency
* operations.
*
* On success, an action handle is returned and \c *status is set to
* \c MTAPI_SUCCESS. On error, \c *status is set to the appropriate error
* defined below. In the case where the action already exists, \c status will
* be set to \c MTAPI_ERR_ACTION_EXISTS and the handle returned will not be a
* valid handle.
* <table>
* <tr>
* <th>Error code</th>
* <th>Description</th>
* </tr>
* <tr>
* <td>\c MTAPI_ERR_JOB_INVALID</td>
* <td>The \c job_id is not a valid job ID, i.e., no action was created for
* that ID or the action has been deleted.</td>
* </tr>
* <tr>
* <td>\c MTAPI_ERR_ACTION_EXISTS</td>
* <td>This action is already created.</td>
* </tr>
* <tr>
* <td>\c MTAPI_ERR_ACTION_LIMIT</td>
* <td>Exceeded maximum number of actions allowed.</td>
* </tr>
* <tr>
* <td>\c MTAPI_ERR_NODE_NOTINIT</td>
* <td>The calling node is not initialized.</td>
* </tr>
* <tr>
* <td>\c MTAPI_ERR_UNKNOWN</td>
* <td>The kernel could not be compiled or no OpenCL device was
* available.</td>
* </tr>
* </table>
*
* \see mtapi_action_delete(), mtapi_finalize()
*
* \returns Handle to newly created Zynq action, invalid handle on error
* \threadsafe
* \ingroup C_MTAPI_ZYNQ
*/
mtapi_action_hndl_t mtapi_zynq_action_create(
MTAPI_IN mtapi_job_id_t job_id, /**< [in] Job id */
MTAPI_IN char* uio_name, /**< [in] Name of the UIO node in the device tree, may be \c MTAPI_NULL to use /dev/mem for memory mapping*/
MTAPI_IN uint32_t phys_addr, /**< [in] Physical address of the accelerator*/
MTAPI_IN void* node_local_data, /**< [in] Data shared across tasks */
MTAPI_IN mtapi_size_t node_local_data_size,
/**< [in] Size of shared data */
MTAPI_IN uint8_t cacheable, /**< [in] Defines whether buffers are cached or not*/
MTAPI_OUT mtapi_status_t* status /**< [out] Pointer to error code,
may be \c MTAPI_NULL */
);

#ifdef __cplusplus
}
#endif


#endif // EMBB_MTAPI_C_MTAPI_ZYNQ_H_
Loading