Skip to content

Commit

Permalink
Moves headers around and modifies CMake to make core/ctx usable as an…
Browse files Browse the repository at this point in the history
… external library
  • Loading branch information
ilumsden committed Sep 3, 2024
1 parent f61ace5 commit 7cc2cd5
Show file tree
Hide file tree
Showing 19 changed files with 2,703 additions and 2,681 deletions.
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 */
9 changes: 9 additions & 0 deletions include/dyad/core/dyad.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef DYAD_CORE_DYAD_H
#define DYAD_CORE_DYAD_H

// clang-format off
#include <dyad/core/dyad_ctx.h>
#include <dyad/core/dyad_core.h>
// clang-format on

#endif /* DYAD_CORE_DYAD_H */
97 changes: 97 additions & 0 deletions include/dyad/core/dyad_core.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#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 <sys/types.h>
#include <unistd.h>

#ifdef __cplusplus
#include <cstdio>
#include <cstdlib>
#else
#include <stdbool.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
DYAD_DLL_EXPORTED extern const struct dyad_ctx dyad_ctx_default;

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.
69 changes: 0 additions & 69 deletions src/dyad/common/dyad_structures.h

This file was deleted.

69 changes: 69 additions & 0 deletions src/dyad/common/dyad_structures_int.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#ifndef DYAD_COMMON_STRUCTURES_INT_H
#define DYAD_COMMON_STRUCTURES_INT_H

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

#include <dyad/common/dyad_structures.h>

#ifdef __cplusplus
#include <cstdint>
#else
#include <stdbool.h>
#include <stdint.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

/**
* @struct dyad_ctx
*/
struct dyad_ctx {
// Internal
void *h; // the Flux handle for DYAD
struct dyad_dtl *dtl_handle; // Opaque handle to DTL info
const char *fname; // Used to track which file is getting processed.
bool use_fs_locks; // Used to track if fs locks should be used.
char *prod_real_path; // producer managed real path
char *cons_real_path; // consumer managed real path
uint32_t prod_managed_len; // length of producer path managed by DYAD
uint32_t cons_managed_len; // length of consumer path managed by DYAD
uint32_t prod_real_len; // length of producer managed real path
uint32_t cons_real_len; // length of consumer managed real path
uint32_t prod_managed_hash; // hash of producer path managed by DYAD
uint32_t cons_managed_hash; // hash of consumer path managed by DYAD
uint32_t prod_real_hash; // hash of producer managed real path
uint32_t cons_real_hash; // hash of consumer managed real path
uint32_t delim_len; // length of path delimiter
// User Facing
bool debug; // if true, perform debug logging
bool check; // if true, perform some check logging
bool reenter; // if false, do not recursively enter DYAD
bool initialized; // if true, DYAD is initialized
bool shared_storage; // if true, the managed path is shared
bool async_publish; // Enable asynchronous publish by producer
bool fsync_write; // Apply fsync after write by producer
unsigned int key_depth; // Depth of bins for the Flux KVS
unsigned int key_bins; // Number of bins for the Flux KVS
uint32_t rank; // Flux rank for DYAD
uint32_t service_mux; // Number of Flux brokers sharing node-local storage
uint32_t node_idx; // Index of the node hosting broker(s)
int pid; // unix process id, obtained by getpid()
char *kvs_namespace; // Flux KVS namespace for DYAD
char *prod_managed_path; // producer path managed by DYAD
char *cons_managed_path; // consumer path managed by DYAD
bool
relative_to_managed_path; // relative path is relative to the managed path
};
typedef void *ucx_ep_cache_h;

#ifdef __cplusplus
}
#endif

#endif // DYAD_COMMON_STRUCTURES_INT_H
64 changes: 42 additions & 22 deletions src/dyad/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
set(DYAD_CORE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/dyad_core.c)
set(DYAD_CORE_PRIVATE_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../common/dyad_rc.h
${CMAKE_CURRENT_SOURCE_DIR}/../common/dyad_dtl.h
${CMAKE_CURRENT_SOURCE_DIR}/../common/dyad_envs.h
${CMAKE_CURRENT_SOURCE_DIR}/../common/dyad_logging.h
set(DYAD_CORE_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_ctx.h
${CMAKE_CURRENT_SOURCE_DIR}/dyad_core.h)
set(DYAD_CORE_PUBLIC_HEADERS)
${CMAKE_CURRENT_SOURCE_DIR}/dyad_core_int.h)
set(DYAD_CORE_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/core/dyad_core.h
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/dyad/core/dyad_ctx.h)

set(DYAD_CTX_SRC ${CMAKE_CURRENT_SOURCE_DIR}/dyad_ctx.c)
set(DYAD_CTX_PRIVATE_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/dyad_ctx.h
${CMAKE_CURRENT_SOURCE_DIR}/../common/dyad_rc.h
${CMAKE_CURRENT_SOURCE_DIR}/../common/dyad_dtl.h
${CMAKE_CURRENT_SOURCE_DIR}/../common/dyad_envs.h
${CMAKE_CURRENT_SOURCE_DIR}/../common/dyad_logging.h
set(DYAD_CTX_PRIVATE_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../common/dyad_logging.h
${CMAKE_CURRENT_SOURCE_DIR}/../common/dyad_profiler.h)
set(DYAD_CTX_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/dyad/core/dyad_ctx.h
${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)

add_library(${PROJECT_NAME}_ctx SHARED ${DYAD_CTX_SRC}
${DYAD_CTX_PUBLIC_HEADERS} ${DYAD_CTX_PRIVATE_HEADERS})
target_compile_definitions(${PROJECT_NAME}_ctx PUBLIC BUILDING_DYAD=1)
target_compile_definitions(${PROJECT_NAME}_ctx PUBLIC DYAD_HAS_CONFIG)
target_include_directories(${PROJECT_NAME}_ctx PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${DYAD_INSTALL_INCLUDE_DIR}>)
target_include_directories(${PROJECT_NAME}_ctx SYSTEM PRIVATE ${JANSSON_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME}_ctx SYSTEM PRIVATE ${FluxCore_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}_ctx PRIVATE ${PROJECT_NAME}_dtl ${PROJECT_NAME}_utils)

add_library(${PROJECT_NAME}_core SHARED ${DYAD_CORE_SRC}
${DYAD_CORE_PUBLIC_HEADERS} ${DYAD_CORE_PRIVATE_HEADERS})
set_target_properties(${PROJECT_NAME}_core PROPERTIES CMAKE_INSTALL_RPATH
"${CMAKE_INSTALL_PREFIX}/${DYAD_LIBDIR}")
target_link_libraries(${PROJECT_NAME}_core PRIVATE Jansson::Jansson flux::core)
target_link_libraries(${PROJECT_NAME}_core PRIVATE ${PROJECT_NAME}_ctx ${PROJECT_NAME}_utils
target_link_libraries(${PROJECT_NAME}_core PRIVATE ${PROJECT_NAME}_utils
${PROJECT_NAME}_murmur3 ${PROJECT_NAME}_dtl)
target_link_libraries(${PROJECT_NAME}_core PUBLIC ${PROJECT_NAME}_ctx)

target_compile_definitions(${PROJECT_NAME}_core PUBLIC BUILDING_DYAD=1)
target_compile_definitions(${PROJECT_NAME}_core PUBLIC DYAD_HAS_CONFIG)
Expand All @@ -35,14 +49,6 @@ target_include_directories(${PROJECT_NAME}_core PUBLIC
target_include_directories(${PROJECT_NAME}_core SYSTEM PRIVATE ${JANSSON_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME}_core SYSTEM PRIVATE ${FluxCore_INCLUDE_DIRS})

add_library(${PROJECT_NAME}_ctx SHARED ${DYAD_CTX_SRC}
${DYAD_CTX_PRIVATE_HEADERS})
target_compile_definitions(${PROJECT_NAME}_ctx PUBLIC BUILDING_DYAD=1)
target_compile_definitions(${PROJECT_NAME}_ctx PUBLIC DYAD_HAS_CONFIG)
target_include_directories(${PROJECT_NAME}_ctx SYSTEM PRIVATE ${JANSSON_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME}_ctx SYSTEM PRIVATE ${FluxCore_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}_ctx PRIVATE ${PROJECT_NAME}_dtl ${PROJECT_NAME}_utils)

if (TARGET DYAD_C_FLAGS_werror)
target_link_libraries(${PROJECT_NAME}_core PRIVATE DYAD_C_FLAGS_werror)
target_link_libraries(${PROJECT_NAME}_ctx PRIVATE DYAD_C_FLAGS_werror)
Expand All @@ -56,13 +62,27 @@ endif()
if(DYAD_PROFILER STREQUAL "DFTRACER")
target_link_libraries(${PROJECT_NAME}_core PRIVATE ${DFTRACER_LIBRARIES})
endif()

set(DYAD_CLIENT_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/dyad/core/dyad.h)
add_library(${PROJECT_NAME}_client INTERFACE)
target_link_libraries(${PROJECT_NAME}_client PULBIC ${PROJECT_NAME}_ctx ${PROJECT_NAME}_core)
target_include_directories(${PROJECT_NAME}_client PUBLIC
$<INSTALL_INTERFACE:${DYAD_INSTALL_INCLUDE_DIR}>)

install(
TARGETS ${PROJECT_NAME}_core ${PROJECT_NAME}_ctx
TARGETS ${PROJECT_NAME}_core ${PROJECT_NAME}_ctx ${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_CORE_PUBLIC_HEADERS}" STREQUAL "")
dyad_install_headers("${DYAD_CORE_PUBLIC_HEADERS}" ${CMAKE_CURRENT_SOURCE_DIR})
endif()
if(NOT "${DYAD_CTX_PUBLIC_HEADERS}" STREQUAL "")
dyad_install_headers("${DYAD_CTX_PUBLIC_HEADERS}" ${CMAKE_CURRENT_SOURCE_DIR})
endif()
if(NOT "${DYAD_CLIENT_PUBLIC_HEADERS}" STREQUAL "")
dyad_install_headers("${DYAD_CLIENT_PUBLIC_HEADERS}" ${CMAKE_CURRENT_SOURCE_DIR})
endif()
Loading

0 comments on commit 7cc2cd5

Please sign in to comment.