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

Makes Core into Core and Client and Exposes Client API to Users #120

Merged
merged 3 commits into from
Dec 16, 2024
Merged
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
99 changes: 99 additions & 0 deletions include/dyad/client/dyad_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#ifndef DYAD_CORE_DYAD_CORE_H
#define DYAD_CORE_DYAD_CORE_H

#if defined(DYAD_HAS_CONFIG)
#include <dyad/dyad_config.hpp>
#else
#error "no config"
#endif

#include <dyad/common/dyad_rc.h>
#include <dyad/common/dyad_structures.h>
#include <dyad/core/dyad_ctx.h>
#include <sys/types.h>
#include <unistd.h>

#ifdef __cplusplus
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#else
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif
#if DYAD_PERFFLOW
#define DYAD_CORE_FUNC_MODS __attribute__((annotate("@critical_path()"))) static
#else
#define DYAD_CORE_FUNC_MODS static inline
#endif

struct dyad_metadata {
char *fpath;
uint32_t owner_rank;
};
typedef struct dyad_metadata dyad_metadata_t;

/**
* @brief Wrapper function that performs all the common tasks needed
* of a producer
* @param[in] ctx the DYAD context for the operation
* @param[in] fname the name of the file being "produced"
*
* @return An error code from dyad_rc.h
*/
DYAD_PFA_ANNOTATE DYAD_DLL_EXPORTED dyad_rc_t dyad_produce(dyad_ctx_t *ctx,
const char *fname);

/**
* @brief Obtain DYAD metadata for a file in the consumer-managed directory
* @param[in] ctx the DYAD context for the operation
* @param[in] fname the name of the file for which metadata is obtained
* @param[in] should_wait if true, wait for the file to be produced before
* returning
* @param[out] mdata a dyad_metadata_t object containing the metadata for
* the file
*
* @return An error code from dyad_rc.h
*/
DYAD_PFA_ANNOTATE DYAD_DLL_EXPORTED dyad_rc_t
dyad_get_metadata(dyad_ctx_t *ctx, const char *fname, bool should_wait,
dyad_metadata_t **mdata);

DYAD_PFA_ANNOTATE DYAD_DLL_EXPORTED dyad_rc_t
dyad_free_metadata(dyad_metadata_t **mdata);

/**
* @brief Wrapper function that performs all the common tasks needed
* of a consumer
* @param[in] ctx the DYAD context for the operation
* @param[in] fname the name of the file being "consumed"
*
* @return An error code from dyad_rc.h
*/
DYAD_PFA_ANNOTATE DYAD_DLL_EXPORTED dyad_rc_t dyad_consume(dyad_ctx_t *ctx,
const char *fname);

/**
* @brief Wrapper function that performs all the common tasks needed
* of a consumer
* @param[in] ctx the DYAD context for the operation
* @param[in] fname the name of the file being "consumed"
* @param[in] mdata a dyad_metadata_t object containing the metadata for the
* file User is responsible for deallocating this object
*
* @return An error code from dyad_rc.h
*/
DYAD_PFA_ANNOTATE DYAD_DLL_EXPORTED dyad_rc_t dyad_consume_w_metadata(
dyad_ctx_t *ctx, const char *fname, const dyad_metadata_t *mdata);

#ifdef __cplusplus
}
#endif

#endif /* DYAD_CORE_DYAD_CORE */
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions include/dyad/common/dyad_structures.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef DYAD_COMMON_STRUCTURES_H
#define DYAD_COMMON_STRUCTURES_H

#if defined(DYAD_HAS_CONFIG)
#include <dyad/dyad_config.hpp>
#else
#error "no config"
#endif

struct dyad_ctx;
typedef struct dyad_ctx dyad_ctx_t;

#endif /* DYAD_COMMON_STRUCTURES_H */
64 changes: 28 additions & 36 deletions src/dyad/core/dyad_ctx.h → include/dyad/core/dyad_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
#error "no config"
#endif

#include <dyad/common/dyad_rc.h>
#include <dyad/common/dyad_dtl.h>
#include <dyad/common/dyad_rc.h>
#include <dyad/common/dyad_structures.h>

#ifdef __cplusplus
extern "C" {
#endif

DYAD_DLL_EXPORTED dyad_ctx_t* dyad_ctx_get ();
DYAD_DLL_EXPORTED void dyad_ctx_init (dyad_dtl_comm_mode_t dtl_comm_mode,
void* flux_handle);
DYAD_DLL_EXPORTED void dyad_ctx_fini ();
DYAD_DLL_EXPORTED extern const struct dyad_ctx dyad_ctx_default;

DYAD_DLL_EXPORTED dyad_ctx_t *dyad_ctx_get();
DYAD_DLL_EXPORTED void dyad_ctx_init(dyad_dtl_comm_mode_t dtl_comm_mode,
void *flux_handle);
DYAD_DLL_EXPORTED void dyad_ctx_fini();

/**
* @brief Intialize the DYAD context
Expand All @@ -34,58 +36,48 @@ DYAD_DLL_EXPORTED void dyad_ctx_fini ();
* @param[in] service_mux number of brokers sharing node-local storage
* @param[in] kvs_namespace Flux KVS namespace to be used for this
* instance of DYAD
* @param[in] relative_to_managed_path relative path is relative to the managed path
* Which one of the managed path it will be relative to
* depends on the context and it could be either of
* producer or consumer's path. This is only applicable
* when there is only one of each.
* @param[in] relative_to_managed_path relative path is relative to the managed
* path Which one of the managed path it will be relative to depends on the
* context and it could be either of producer or consumer's path. This is only
* applicable when there is only one of each.
* @param[in] dtl_mode_str DTL mode
* @param[in] dtl_comm_mode DTL comm mode
* @param[in] flux_handle Flux handle (flux_t*). If NULL, it will be obtained via
* `flux_open()`
* @param[in] flux_handle Flux handle (flux_t*). If NULL, it will be
* obtained via `flux_open()`
*
* @return An error code from dyad_rc.h
*/
DYAD_DLL_EXPORTED dyad_rc_t dyad_init (bool debug,
bool check,
bool shared_storage,
bool reinit,
bool async_publish,
bool fsync_write,
unsigned int key_depth,
unsigned int key_bins,
unsigned int service_mux,
const char* kvs_namespace,
const char* prod_managed_path,
const char* cons_managed_path,
bool relative_to_managed_path,
const char* dtl_mode_str,
const dyad_dtl_comm_mode_t dtl_comm_mode,
void* flux_handle);
DYAD_DLL_EXPORTED dyad_rc_t dyad_init(
bool debug, bool check, bool shared_storage, bool reinit,
bool async_publish, bool fsync_write, unsigned int key_depth,
unsigned int key_bins, unsigned int service_mux, const char *kvs_namespace,
const char *prod_managed_path, const char *cons_managed_path,
bool relative_to_managed_path, const char *dtl_mode_str,
const dyad_dtl_comm_mode_t dtl_comm_mode, void *flux_handle);

/**
* @brief Intialize the DYAD context using environment variables
*
* @return An error code from dyad_rc.h
*/
DYAD_DLL_EXPORTED dyad_rc_t dyad_init_env (const dyad_dtl_comm_mode_t dtl_comm_mode,
void* flux_handle);
DYAD_DLL_EXPORTED dyad_rc_t
dyad_init_env(const dyad_dtl_comm_mode_t dtl_comm_mode, void *flux_handle);

/**
* @brief Reset producer path. Can be used by the module
* @param[in] producer path string
*
* @return An error code from dyad_rc.h
*/
DYAD_DLL_EXPORTED dyad_rc_t dyad_set_prod_path (const char* path);
DYAD_DLL_EXPORTED dyad_rc_t dyad_set_prod_path(const char *path);

/**
* @brief Reset consumer path. Can be used by the module
* @param[in] consumer path string
*
* @return An error code from dyad_rc.h
*/
DYAD_DLL_EXPORTED dyad_rc_t dyad_set_cons_path (const char* path);
DYAD_DLL_EXPORTED dyad_rc_t dyad_set_cons_path(const char *path);

/**
* @brief Reset dtl mode. Can be used by the module
Expand All @@ -94,23 +86,23 @@ DYAD_DLL_EXPORTED dyad_rc_t dyad_set_cons_path (const char* path);
*
* @return An error code from dyad_rc.h
*/
DYAD_DLL_EXPORTED dyad_rc_t dyad_set_and_init_dtl_mode (const char* dtl_mode_name,
dyad_dtl_comm_mode_t dtl_comm_mode);
DYAD_DLL_EXPORTED dyad_rc_t dyad_set_and_init_dtl_mode(
const char *dtl_mode_name, dyad_dtl_comm_mode_t dtl_comm_mode);

/**
* Reset the contents of the ctx to the default values and deallocate
* internal objects linked. However, do not destroy the ctx object itself.
* This is needed for wrapper to handle dyad exceptions as the wrapper requires
* ctx for it's lifetime
*/
DYAD_DLL_EXPORTED dyad_rc_t dyad_clear ();
DYAD_DLL_EXPORTED dyad_rc_t dyad_clear();

/**
* @brief Finalizes the DYAD instance and deallocates the context
*
* @return An error code from dyad_rc.h
*/
DYAD_DLL_EXPORTED dyad_rc_t dyad_finalize ();
DYAD_DLL_EXPORTED dyad_rc_t dyad_finalize();

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions src/dyad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include_directories(${CMAKE_BINARY_DIR}/include)
add_subdirectory(utils)
add_subdirectory(dtl)
add_subdirectory(core)
add_subdirectory(client)
add_subdirectory(modules)
add_subdirectory(wrapper)
add_subdirectory(stream)
Expand Down
54 changes: 54 additions & 0 deletions src/dyad/client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
set(DYAD_CLIENT_SRC ${CMAKE_CURRENT_SOURCE_DIR}/dyad_client.c)
set(DYAD_CLIENT_PRIVATE_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../common/dyad_logging.h
${CMAKE_CURRENT_SOURCE_DIR}/../common/dyad_profiler.h
${CMAKE_CURRENT_SOURCE_DIR}/../common/dyad_structures_int.h
${CMAKE_CURRENT_SOURCE_DIR}/../dtl/dyad_dtl_api.h
${CMAKE_CURRENT_SOURCE_DIR}/../utils/utils.h
${CMAKE_CURRENT_SOURCE_DIR}/../utils/murmur3.h
${CMAKE_CURRENT_SOURCE_DIR}/dyad_client_int.h)
set(DYAD_CLIENT_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/dyad/common/dyad_rc.h
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/dyad/common/dyad_dtl.h
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/dyad/common/dyad_envs.h
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/dyad/common/dyad_structures.h
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/dyad/client/dyad_client.h)

add_library(${PROJECT_NAME}_client SHARED ${DYAD_CLIENT_SRC}
${DYAD_CLIENT_PUBLIC_HEADERS} ${DYAD_CLIENT_PRIVATE_HEADERS})
set_target_properties(${PROJECT_NAME}_client PROPERTIES CMAKE_INSTALL_RPATH
"${CMAKE_INSTALL_PREFIX}/${DYAD_LIBDIR}")
target_link_libraries(${PROJECT_NAME}_client PRIVATE Jansson::Jansson flux::core)
target_link_libraries(${PROJECT_NAME}_client PRIVATE ${PROJECT_NAME}_utils
${PROJECT_NAME}_murmur3 ${PROJECT_NAME}_dtl)
target_link_libraries(${PROJECT_NAME}_client PUBLIC ${PROJECT_NAME}_ctx)

target_compile_definitions(${PROJECT_NAME}_client PUBLIC BUILDING_DYAD=1)
target_compile_definitions(${PROJECT_NAME}_client PUBLIC DYAD_HAS_CONFIG)
target_include_directories(${PROJECT_NAME}_client PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/src> # will be used for generated code
$<INSTALL_INTERFACE:${DYAD_INSTALL_INCLUDE_DIR}>) # wil be used for sub projects
target_include_directories(${PROJECT_NAME}_client SYSTEM PRIVATE ${JANSSON_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME}_client SYSTEM PRIVATE ${FluxCore_INCLUDE_DIRS})

if (TARGET DYAD_C_FLAGS_werror)
target_link_libraries(${PROJECT_NAME}_client PRIVATE DYAD_C_FLAGS_werror)
endif ()

if(DYAD_PROFILER STREQUAL "PERFFLOW_ASPECT")
target_link_libraries(${PROJECT_NAME}_client PRIVATE perfflowaspect::perfflowaspect)
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${perfflowaspect_INCLUDE_DIRS})
target_compile_definitions(${PROJECT_NAME}_client PRIVATE DYAD_PERFFLOW=1)
endif()
if(DYAD_PROFILER STREQUAL "DFTRACER")
target_link_libraries(${PROJECT_NAME}_client PRIVATE ${DFTRACER_LIBRARIES})
endif()

install(
TARGETS ${PROJECT_NAME}_client
EXPORT ${DYAD_EXPORTED_TARGETS}
LIBRARY DESTINATION ${DYAD_INSTALL_LIB_DIR}
ARCHIVE DESTINATION ${DYAD_INSTALL_LIB_DIR}
RUNTIME DESTINATION ${DYAD_INSTALL_BIN_DIR}
)
if(NOT "${DYAD_CLIENT_PUBLIC_HEADERS}" STREQUAL "")
dyad_install_headers("${DYAD_CLIENT_PUBLIC_HEADERS}" ${CMAKE_CURRENT_SOURCE_DIR})
endif()
Loading