Lightweight Parallel Foundations 1.0.1-alpha 2023-06-26T11:02:34Z
A high performance and model-compliant communication layer
core.h
Go to the documentation of this file.
1
2/*
3 * Copyright 2021 Huawei Technologies Co., Ltd.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef LPFLIB_CORE_H
19#define LPFLIB_CORE_H
20
629#ifndef DOXYGEN
630
631
632// Symbol visibility macros
633// slightly adapted copy from https://gcc.gnu.org/wiki/Visibility
634//
635// Generic helper definitions for shared library support
636#if defined _WIN32 || defined __CYGWIN__
637 #define _LPFLIB_HELPER_DLL_IMPORT __declspec(dllimport)
638 #define _LPFLIB_HELPER_DLL_EXPORT __declspec(dllexport)
639 #define _LPFLIB_HELPER_DLL_LOCAL
640
641 #define _LPFLIB_HELPER_VAR_IMPORT __declspec(dllimport)
642 #define _LPFLIB_HELPER_VAR_EXPORT __declspec(dllexport)
643#else
644 #if __GNUC__ >= 4
645 #define _LPFLIB_HELPER_DLL_IMPORT __attribute__ ((visibility ("default")))
646 #define _LPFLIB_HELPER_DLL_EXPORT __attribute__ ((visibility ("default")))
647 #define _LPFLIB_HELPER_DLL_LOCAL __attribute__ ((visibility ("hidden")))
648 #else
649 #define _LPFLIB_HELPER_DLL_IMPORT
650 #define _LPFLIB_HELPER_DLL_EXPORT
651 #define _LPFLIB_HELPER_DLL_LOCAL
652 #endif
653
654 #define _LPFLIB_HELPER_VAR_IMPORT
655 #define _LPFLIB_HELPER_VAR_EXPORT
656#endif
657
658// Now we use the generic helper definitions above to define _LPFLIB_API
659// and _LPFLIB_LOCAL. _LPFLIB_API is used for the public API symbols.
660// It either DLL imports or DLL exports (or does nothing for static build)
661// _LPFLIB_LOCAL is used for non-api symbols.
662
663#ifdef _LPFLIB_DLL // defined if _LPFLIB is compiled as a DLL
664 #ifdef _LPFLIB_DLL_EXPORTS // defined if we are building the _LPFLIB DLL (instead of using it)
665 #define _LPFLIB_API _LPFLIB_HELPER_DLL_EXPORT
666 #define _LPFLIB_VAR _LPFLIB_HELPER_VAR_EXPORT
667 #else
668 #define _LPFLIB_API _LPFLIB_HELPER_DLL_IMPORT
669 #define _LPFLIB_VAR _LPFLIB_HELPER_VAR_IMPORT
670 #endif // _LPFLIB_DLL_EXPORTS
671 #define _LPFLIB_LOCAL _LPFLIB_HELPER_DLL_LOCAL
672#else // _LPFLIB_DLL is not defined: this means _LPFLIB is a static lib.
673 #define _LPFLIB_API
674 #define _LPFLIB_VAR
675 #define _LPFLIB_LOCAL
676#endif // _LPFLIB_DLL
677
678
679#endif // DOXYGEN
680
681#include <lpf/static_dispatch.h>
682
683
684// import size_t data type for the implementation
685#ifndef DOXYGEN
686
687#ifdef __cplusplus
688#include <cstddef>
689#else
690#include <stddef.h>
691#endif
692
693#endif // DOXYGEN
694
695
696#ifdef __cplusplus
697extern "C" {
698#endif
699
706#define _LPF_VERSION 202000L
707
723#define _LPF_INCLUSIVE_MEMORY 202000L
724
737#ifdef DOXYGEN
738#define _LPF_EXCLUSIVE_MEMORY 202000L
739#endif
740
775typedef void * lpf_t;
776
785#ifdef DOXYGEN
786typedef ... lpf_pid_t;
787#else
788typedef unsigned lpf_pid_t;
789#endif
790
800typedef void (*lpf_func_t) ();
801
802
821typedef struct lpf_args
822{
824 const void * input;
825
828
830 void * output;
831
834
837
839 size_t f_size;
840
841} lpf_args_t;
842
858extern _LPFLIB_VAR const lpf_args_t LPF_NO_ARGS;
859
870#ifdef DOXYGEN
871typedef ... lpf_err_t;
872#else
873typedef int lpf_err_t;
874#endif
875
892extern _LPFLIB_VAR const lpf_err_t LPF_SUCCESS;
893
898extern _LPFLIB_VAR const lpf_err_t LPF_ERR_OUT_OF_MEMORY;
899
904extern _LPFLIB_VAR const lpf_err_t LPF_ERR_FATAL;
905
918#ifdef DOXYGEN
919typedef ... lpf_init_t;
920#else
921typedef void * lpf_init_t;
922#endif
923
940#ifdef DOXYGEN
941typedef ... lpf_sync_attr_t;
942#else
943typedef int lpf_sync_attr_t;
944#endif
945
956typedef struct lpf_machine {
957
967
979
1007 double (*g) (lpf_pid_t p, size_t min_msg_size, lpf_sync_attr_t attr);
1008
1030 double (*l) (lpf_pid_t p, size_t min_msg_size, lpf_sync_attr_t attr);
1031
1033
1041#ifdef DOXYGEN
1042typedef ... lpf_memslot_t;
1043#else
1044
1045#ifdef __cplusplus
1046typedef std::size_t lpf_memslot_t;
1047#else
1048typedef size_t lpf_memslot_t;
1049#endif
1050
1051#endif
1052
1064#ifdef DOXYGEN
1065typedef ... lpf_msg_attr_t;
1066#else
1067typedef int lpf_msg_attr_t;
1068#endif
1069
1102typedef void(*lpf_spmd_t) ( const lpf_t ctx, const lpf_pid_t pid, const lpf_pid_t nprocs, const lpf_args_t args );
1103
1104
1113extern _LPFLIB_VAR const lpf_t LPF_NONE;
1114
1129extern _LPFLIB_VAR const lpf_t LPF_ROOT;
1130
1137extern _LPFLIB_VAR const lpf_init_t LPF_INIT_NONE;
1138
1145extern _LPFLIB_VAR const lpf_sync_attr_t LPF_SYNC_DEFAULT;
1146
1153extern _LPFLIB_VAR const lpf_msg_attr_t LPF_MSG_DEFAULT;
1154
1161extern _LPFLIB_VAR const lpf_pid_t LPF_MAX_P;
1162
1167extern _LPFLIB_VAR const lpf_machine_t LPF_INVALID_MACHINE;
1168
1173extern _LPFLIB_VAR const lpf_memslot_t LPF_INVALID_MEMSLOT;
1174
1359extern _LPFLIB_API
1361 lpf_t ctx,
1362 lpf_pid_t P,
1363 lpf_spmd_t spmd,
1364 lpf_args_t args
1365);
1366
1476extern _LPFLIB_API
1478 lpf_init_t init,
1479 lpf_spmd_t spmd,
1480 lpf_args_t args
1481);
1482
1544extern _LPFLIB_API
1546 lpf_t ctx,
1547 lpf_spmd_t spmd,
1548 lpf_args_t args
1549);
1550
1633extern _LPFLIB_API
1635 lpf_t ctx,
1636 void * pointer,
1637 size_t size,
1638 lpf_memslot_t * memslot
1639);
1640
1704extern _LPFLIB_API
1706 lpf_t ctx,
1707 void * pointer,
1708 size_t size,
1709 lpf_memslot_t * memslot
1710);
1711
1744extern _LPFLIB_API
1746 lpf_t ctx,
1747 lpf_memslot_t memslot
1748);
1749
1871extern _LPFLIB_API
1873 lpf_t ctx,
1874 lpf_memslot_t src_slot,
1875 size_t src_offset,
1876 lpf_pid_t dst_pid,
1877 lpf_memslot_t dst_slot,
1878 size_t dst_offset,
1879 size_t size,
1880 lpf_msg_attr_t attr
1881);
1882
1999extern _LPFLIB_API
2001 lpf_t ctx,
2002 lpf_pid_t src_pid,
2003 lpf_memslot_t src_slot,
2004 size_t src_offset,
2005 lpf_memslot_t dst_slot,
2006 size_t dst_offset,
2007 size_t size,
2008 lpf_msg_attr_t attr
2009);
2010
2058extern _LPFLIB_API
2060
2094extern _LPFLIB_API
2096
2207extern _LPFLIB_API
2209
2315extern _LPFLIB_API
2317
2318#ifdef __cplusplus
2319}
2320#endif
2321
2363#endif
lpf_err_t lpf_probe(lpf_t ctx, lpf_machine_t *params)
typedef lpf_sync_attr_t
Definition: core.h:941
const lpf_args_t LPF_NO_ARGS
lpf_err_t lpf_register_global(lpf_t ctx, void *pointer, size_t size, lpf_memslot_t *memslot)
lpf_err_t lpf_rehook(lpf_t ctx, lpf_spmd_t spmd, lpf_args_t args)
const lpf_t LPF_ROOT
typedef lpf_memslot_t
Definition: core.h:1042
const lpf_init_t LPF_INIT_NONE
const lpf_pid_t LPF_MAX_P
lpf_err_t lpf_resize_memory_register(lpf_t ctx, size_t max_regs)
lpf_err_t lpf_resize_message_queue(lpf_t ctx, size_t max_msgs)
lpf_err_t lpf_deregister(lpf_t ctx, lpf_memslot_t memslot)
void(* lpf_func_t)()
Definition: core.h:800
lpf_err_t lpf_register_local(lpf_t ctx, void *pointer, size_t size, lpf_memslot_t *memslot)
void(* lpf_spmd_t)(const lpf_t ctx, const lpf_pid_t pid, const lpf_pid_t nprocs, const lpf_args_t args)
Definition: core.h:1102
lpf_err_t lpf_exec(lpf_t ctx, lpf_pid_t P, lpf_spmd_t spmd, lpf_args_t args)
lpf_err_t lpf_get(lpf_t ctx, lpf_pid_t src_pid, lpf_memslot_t src_slot, size_t src_offset, lpf_memslot_t dst_slot, size_t dst_offset, size_t size, lpf_msg_attr_t attr)
const lpf_msg_attr_t LPF_MSG_DEFAULT
lpf_err_t lpf_hook(lpf_init_t init, lpf_spmd_t spmd, lpf_args_t args)
const lpf_memslot_t LPF_INVALID_MEMSLOT
const lpf_machine_t LPF_INVALID_MACHINE
lpf_err_t lpf_sync(lpf_t ctx, lpf_sync_attr_t attr)
typedef lpf_init_t
Definition: core.h:919
typedef lpf_msg_attr_t
Definition: core.h:1065
const lpf_sync_attr_t LPF_SYNC_DEFAULT
void * lpf_t
Definition: core.h:775
typedef lpf_pid_t
Definition: core.h:786
typedef lpf_err_t
Definition: core.h:871
const lpf_t LPF_NONE
lpf_err_t lpf_put(lpf_t ctx, lpf_memslot_t src_slot, size_t src_offset, lpf_pid_t dst_pid, lpf_memslot_t dst_slot, size_t dst_offset, size_t size, lpf_msg_attr_t attr)
const lpf_err_t LPF_ERR_OUT_OF_MEMORY
const lpf_err_t LPF_ERR_FATAL
const lpf_err_t LPF_SUCCESS
Definition: core.h:822
size_t output_size
Definition: core.h:833
size_t input_size
Definition: core.h:827
const void * input
Definition: core.h:824
void * output
Definition: core.h:830
const lpf_func_t * f_symbols
Definition: core.h:836
size_t f_size
Definition: core.h:839
Definition: core.h:956
lpf_pid_t free_p
Definition: core.h:978
lpf_pid_t p
Definition: core.h:966