Getting started with Bake

Installing Bake

Bake can be installed using Spack as follows.

spack install mochi-bake +bedrock

The +bedrock variant will enable Bedrock support, which will be useful for spinning up a Bake server without having to write code. The spack info mochi-bake command can be used to show the list of variants available.

In the following sections, the code can be compiled and linked against the bake-server and bake-client libraries, which can be found either by calling pkg-config --libs --cflags bake-server and pkg-config --libs --cflags bake-client with PkgConfig. Bake does not currently provide an admin library.

Starting a Bake provider and creating a target

The following code shows how to use the Bake server library to register a Bake provider.

#include <assert.h>
#include <stdio.h>
#include <margo.h>
#include <bake-server.h>

int main(int argc, char** argv)
{
    margo_instance_id mid = margo_init("na+sm", MARGO_SERVER_MODE, 0, 0);
    assert(mid);

    hg_addr_t my_address;
    margo_addr_self(mid, &my_address);
    char addr_str[128];
    size_t addr_str_size = 128;
    margo_addr_to_string(mid, addr_str, &addr_str_size, my_address);
    margo_addr_free(mid,my_address);

    margo_set_log_level(mid, MARGO_LOG_INFO);
    margo_info(mid, "Server running at address %s", addr_str);

    bake_provider_t provider = NULL;
    struct bake_provider_init_info init_info = BAKE_PROVIDER_INIT_INFO_INITIALIZER;

    int ret = bake_provider_register(mid, 42, &init_info, &provider);
    assert(ret == BAKE_SUCCESS);

    bake_target_id_t tid;

    ret = bake_provider_create_target(
        provider, "pmem:/dev/shm/mytarget.dat",
        8388608, &tid);
    assert(ret == BAKE_SUCCESS);

    char tid_str[37];
    ret = bake_target_id_to_string(tid, tid_str, 37);
    margo_info(mid, "Target ID is %s", tid_str);

    margo_wait_for_finalize(mid);

    return 0;
}

The bake_provider_register function is used to register a Bake provider.

The bake_provider_create_target function is used to create a storage target. The path to the target is provided, prefixed with either pmem: or file:. The former uses the PMEM library to manage data in a fixed-size file on a persistent memory device. The latter uses a set of files, accessed using classical POSIX functions, to store data.

Targets are uniquely identified using bake_target_id_t, which contains a uuid. The bake_target_id_to_string function can be used to print an ASCII version of this identifier for later use.

Starting a Bake provider via Bedrock

If Bake has been built with Bedrock support, Bedrock can spin up a Bake provider using the following JSON configuration.

{
    "libraries": {
        "bake": "libbake-bedrock.so"
    },
    "providers": [
        {
            "name" : "my_bake_provider",
            "type" : "bake",
            "provider_id" : 42,
            "pool" : "__primary__",
            "config" : {
                "pipeline_enable":true,
                "pmem_backend":{
                    "targets":[
                        "/dev/shm/mytarget.dat"
                    ]
                }
            },
            "dependencies" : {}
        }
    ]
}

The path to the target is specified in the pmem_backend (or file_backend) array.

The current configuration code does not allow creating a target. The target must have been created beforehand at the specified path. This can be done using the bake-mkpool utility, which Bake provides:

bake-mkpool -s 8M "pmem:/dev/shm/mytarget.dat"