#include "mlx.h"
static int mlx_domain_close(fid_t fid)
{
struct mlx_domain *domain;
int status;
domain = container_of( fid,
struct mlx_domain,
u_domain.domain_fid.fid);
ucp_cleanup(domain->context);
status = ofi_domain_close( &(domain->u_domain));
if (!status) {
util_buf_pool_destroy(domain->fast_path_pool);
free(domain);
}
return status;
}
static struct fi_ops mlx_fi_ops = {
.size = sizeof(struct fi_ops),
.close = mlx_domain_close,
};
struct fi_ops_domain mlx_domain_ops = {
.size = sizeof(struct fi_ops_domain),
.av_open = mlx_av_open,
.cq_open = mlx_cq_open,
.endpoint = mlx_ep_open,
.poll_open = fi_poll_create,
};
struct fi_ops_mr mlx_mr_ops = {
.size = sizeof(struct fi_ops_mr),
.reg = fi_no_mr_reg,
.regv = fi_no_mr_regv,
.regattr = fi_no_mr_regattr,
};
int mlx_domain_open(struct fid_fabric *fabric, struct fi_info *info,
struct fid_domain **fid, void *context)
{
ucs_status_t status = UCS_OK;
int ofi_status;
struct mlx_domain* domain;
ucp_params_t params;
if (!info->domain_attr->name ||
strcmp(info->domain_attr->name, FI_MLX_FABRIC_NAME)) {
return -FI_EINVAL;
}
ofi_status = ofi_check_info(&mlx_util_prov, fabric->api_version, info);
if (ofi_status) {
return ofi_status;
}
domain = calloc(1, sizeof(struct mlx_domain));
if (!domain) {
return -ENOMEM;
}
ofi_status = ofi_domain_init(fabric, info, &(domain->u_domain), context);
if (ofi_status) {
goto domain_free;
}
params.features = UCP_FEATURE_TAG;
params.request_size = sizeof(struct mlx_request);
params.request_init = NULL;
params.request_cleanup = NULL;
status = ucp_init(
(const ucp_params_t *)¶ms,
mlx_descriptor.config,
&(domain->context));
if (status != UCS_OK) {
ofi_status = MLX_TRANSLATE_ERRCODE(status);
goto destroy_domain;
}
fastlock_init(&(domain->fpp_lock));
domain->fast_path_pool = util_buf_pool_create(
sizeof(struct mlx_request),
16, 0, 1024 );
if (!domain->fast_path_pool) {
ofi_status = -ENOMEM;
goto cleanup_mlx;
}
domain->u_domain.domain_fid.fid.ops = &mlx_fi_ops;
domain->u_domain.domain_fid.ops = &mlx_domain_ops;
domain->u_domain.domain_fid.mr = &mlx_mr_ops;
*fid = &(domain->u_domain.domain_fid);
return FI_SUCCESS;
cleanup_mlx:
ucp_cleanup(domain->context);
destroy_domain:
ofi_domain_close(&(domain->u_domain));
domain_free:
free(domain);
if (!ofi_status) {
ofi_status = FI_ENETUNREACH;
}
return ofi_status;
}