2005-05-31 21:08:41 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
#include <string.h>
|
2005-07-04 03:31:27 +04:00
|
|
|
#include "opal/util/output.h"
|
2005-07-01 01:28:35 +04:00
|
|
|
#include "mca/mpool/mvapi/mpool_mvapi.h"
|
2005-08-25 19:04:22 +04:00
|
|
|
#include <vapi.h>
|
|
|
|
#include <vapi_types.h>
|
|
|
|
#include <vapi_common.h>
|
2005-05-31 21:08:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializes the mpool module.
|
|
|
|
*/
|
2005-07-01 01:28:35 +04:00
|
|
|
void mca_mpool_mvapi_module_init(mca_mpool_mvapi_module_t* mpool)
|
2005-05-31 21:08:41 +04:00
|
|
|
{
|
2005-07-01 01:28:35 +04:00
|
|
|
mpool->super.mpool_component = &mca_mpool_mvapi_component.super;
|
2005-06-21 19:03:59 +04:00
|
|
|
mpool->super.mpool_base = NULL; /* no base .. */
|
2005-07-01 01:28:35 +04:00
|
|
|
mpool->super.mpool_alloc = mca_mpool_mvapi_alloc;
|
|
|
|
mpool->super.mpool_realloc = mca_mpool_mvapi_realloc;
|
|
|
|
mpool->super.mpool_free = mca_mpool_mvapi_free;
|
|
|
|
mpool->super.mpool_register = mca_mpool_mvapi_register;
|
|
|
|
mpool->super.mpool_deregister = mca_mpool_mvapi_deregister;
|
2005-06-21 19:03:59 +04:00
|
|
|
mpool->super.mpool_finalize = NULL;
|
2005-05-31 21:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* allocate function
|
|
|
|
*/
|
2005-07-01 01:28:35 +04:00
|
|
|
void* mca_mpool_mvapi_alloc(
|
2005-06-21 21:10:28 +04:00
|
|
|
mca_mpool_base_module_t* mpool,
|
|
|
|
size_t size,
|
|
|
|
size_t align,
|
2005-06-25 01:12:38 +04:00
|
|
|
mca_mpool_base_registration_t** registration)
|
2005-05-31 21:08:41 +04:00
|
|
|
{
|
2005-07-15 19:52:13 +04:00
|
|
|
|
|
|
|
void* addr_malloc = (void*)malloc(size + mca_mpool_mvapi_component.page_size);
|
|
|
|
void* addr = (void*) ALIGN_ADDR(addr_malloc, mca_mpool_mvapi_component.page_size_log);
|
|
|
|
if(OMPI_SUCCESS != mpool->mpool_register(mpool, addr, size, registration)) {
|
|
|
|
free(addr_malloc);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
(*registration)->alloc_base = addr_malloc;
|
|
|
|
return addr;
|
2005-06-21 19:03:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* register memory
|
|
|
|
*/
|
2005-07-01 01:28:35 +04:00
|
|
|
int mca_mpool_mvapi_register(mca_mpool_base_module_t* mpool,
|
2005-06-25 01:12:38 +04:00
|
|
|
void *addr,
|
|
|
|
size_t size,
|
|
|
|
mca_mpool_base_registration_t** registration){
|
|
|
|
|
2005-07-01 01:28:35 +04:00
|
|
|
mca_mpool_mvapi_module_t * mpool_module = (mca_mpool_mvapi_module_t*) mpool;
|
|
|
|
mca_mpool_mvapi_registration_t * vapi_reg;
|
2005-06-21 19:03:59 +04:00
|
|
|
VAPI_mrw_t mr_in, mr_out;
|
2005-06-25 01:12:38 +04:00
|
|
|
|
2005-06-21 19:03:59 +04:00
|
|
|
VAPI_ret_t ret;
|
2005-06-25 01:12:38 +04:00
|
|
|
|
2005-06-21 19:03:59 +04:00
|
|
|
memset(&mr_in, 0, sizeof(VAPI_mrw_t));
|
|
|
|
memset(&mr_out, 0, sizeof(VAPI_mrw_t));
|
|
|
|
|
2005-07-01 01:28:35 +04:00
|
|
|
*registration = (mca_mpool_base_registration_t*) OBJ_NEW(mca_mpool_mvapi_registration_t); /* (void*) malloc(sizeof(mca_mpool_base_registration_t)); */
|
|
|
|
vapi_reg = (mca_mpool_mvapi_registration_t*) *registration;
|
2005-06-25 01:12:38 +04:00
|
|
|
vapi_reg->base_reg.mpool = mpool;
|
|
|
|
|
|
|
|
|
|
|
|
vapi_reg->hndl = VAPI_INVAL_HNDL;
|
2005-06-21 19:03:59 +04:00
|
|
|
|
|
|
|
|
2005-08-17 22:23:38 +04:00
|
|
|
mr_in.acl = VAPI_EN_LOCAL_WRITE | VAPI_EN_REMOTE_WRITE | VAPI_EN_REMOTE_READ;
|
2005-06-21 19:03:59 +04:00
|
|
|
mr_in.l_key = 0;
|
|
|
|
mr_in.r_key = 0;
|
|
|
|
mr_in.pd_hndl = mpool_module->hca_pd.pd_tag;
|
|
|
|
mr_in.size = size;
|
|
|
|
mr_in.start = (VAPI_virt_addr_t) (MT_virt_addr_t) addr;
|
|
|
|
mr_in.type = VAPI_MR;
|
|
|
|
|
|
|
|
|
|
|
|
ret = VAPI_register_mr(
|
|
|
|
mpool_module->hca_pd.hca,
|
|
|
|
&mr_in,
|
2005-06-25 01:12:38 +04:00
|
|
|
&vapi_reg->hndl,
|
2005-06-21 19:03:59 +04:00
|
|
|
&mr_out
|
|
|
|
);
|
|
|
|
|
|
|
|
if(VAPI_OK != ret){
|
2005-07-20 21:43:31 +04:00
|
|
|
opal_output(0, "error registering memory: %s ", VAPI_strerror(ret));
|
2005-06-21 19:03:59 +04:00
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-06-25 01:12:38 +04:00
|
|
|
vapi_reg->l_key = mr_out.l_key;
|
|
|
|
vapi_reg->r_key = mr_out.r_key;
|
2005-06-30 09:50:55 +04:00
|
|
|
vapi_reg->base_reg.base = addr;
|
|
|
|
vapi_reg->base_reg.bound = (void*) ((char*) addr + size - 1);
|
2005-06-21 23:38:50 +04:00
|
|
|
|
2005-06-21 19:03:59 +04:00
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* deregister memory
|
|
|
|
*/
|
2005-07-01 01:28:35 +04:00
|
|
|
int mca_mpool_mvapi_deregister(mca_mpool_base_module_t* mpool, void *addr, size_t size,
|
2005-06-25 01:12:38 +04:00
|
|
|
mca_mpool_base_registration_t* registration){
|
2005-06-21 19:03:59 +04:00
|
|
|
|
|
|
|
VAPI_ret_t ret;
|
2005-07-01 01:28:35 +04:00
|
|
|
mca_mpool_mvapi_module_t * mpool_mvapi = (mca_mpool_mvapi_module_t*) mpool;
|
|
|
|
mca_mpool_mvapi_registration_t * vapi_reg;
|
|
|
|
vapi_reg = (mca_mpool_mvapi_registration_t*) registration;
|
2005-06-21 19:03:59 +04:00
|
|
|
ret = VAPI_deregister_mr(
|
2005-07-01 01:28:35 +04:00
|
|
|
mpool_mvapi->hca_pd.hca,
|
2005-06-25 01:12:38 +04:00
|
|
|
vapi_reg->hndl
|
2005-06-21 19:03:59 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
if(VAPI_OK != ret){
|
2005-07-04 03:31:27 +04:00
|
|
|
opal_output(0, "%s: error unpinning vapi memory\n", __func__);
|
2005-06-21 19:03:59 +04:00
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
2005-07-16 01:08:36 +04:00
|
|
|
|
2005-06-21 19:03:59 +04:00
|
|
|
return OMPI_SUCCESS;
|
2005-05-31 21:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* realloc function
|
|
|
|
*/
|
2005-07-01 01:28:35 +04:00
|
|
|
void* mca_mpool_mvapi_realloc(
|
2005-06-21 21:10:28 +04:00
|
|
|
mca_mpool_base_module_t* mpool,
|
|
|
|
void* addr,
|
|
|
|
size_t size,
|
2005-06-25 01:12:38 +04:00
|
|
|
mca_mpool_base_registration_t** registration)
|
2005-05-31 21:08:41 +04:00
|
|
|
{
|
2005-07-15 19:52:13 +04:00
|
|
|
mca_mpool_base_registration_t* old_reg = *registration;
|
|
|
|
void* new_mem = mpool->mpool_alloc(mpool, size, 0, registration);
|
|
|
|
memcpy(new_mem, addr, old_reg->bound - old_reg->base);
|
2005-08-12 18:08:40 +04:00
|
|
|
mpool->mpool_free(mpool, addr, old_reg);
|
2005-07-15 19:52:13 +04:00
|
|
|
return new_mem;
|
2005-05-31 21:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* free function
|
|
|
|
*/
|
2005-07-01 01:28:35 +04:00
|
|
|
void mca_mpool_mvapi_free(mca_mpool_base_module_t* mpool, void * addr,
|
2005-06-25 01:12:38 +04:00
|
|
|
mca_mpool_base_registration_t* registration)
|
2005-05-31 21:08:41 +04:00
|
|
|
{
|
2005-06-22 01:20:23 +04:00
|
|
|
|
2005-07-15 20:05:05 +04:00
|
|
|
mpool->mpool_deregister(mpool, addr, 0, registration);
|
2005-07-15 19:52:13 +04:00
|
|
|
free(registration->alloc_base);
|
2005-06-22 01:20:23 +04:00
|
|
|
|
|
|
|
|
2005-05-31 21:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-22 01:20:23 +04:00
|
|
|
|
|
|
|
|
2005-05-31 21:08:41 +04:00
|
|
|
|