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-12 17:38:54 +04:00
|
|
|
#include "mca/mpool/openib/mpool_openib.h"
|
|
|
|
#include <infiniband/verbs.h>
|
2005-07-15 19:13:19 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2005-09-13 02:28:23 +04:00
|
|
|
#include "mca/rcache/rcache.h"
|
|
|
|
#include "mca/rcache/base/base.h"
|
2005-09-27 06:01:21 +04:00
|
|
|
#include "ompi/mca/mpool/base/base.h"
|
|
|
|
|
|
|
|
extern uint32_t mca_mpool_base_page_size;
|
|
|
|
extern uint32_t mca_mpool_base_page_size_log;
|
2005-09-13 02:28:23 +04:00
|
|
|
|
2005-05-31 21:08:41 +04:00
|
|
|
/*
|
|
|
|
* Initializes the mpool module.
|
|
|
|
*/
|
2005-07-01 01:28:35 +04:00
|
|
|
void mca_mpool_openib_module_init(mca_mpool_openib_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_openib_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_openib_alloc;
|
|
|
|
mpool->super.mpool_realloc = mca_mpool_openib_realloc;
|
|
|
|
mpool->super.mpool_free = mca_mpool_openib_free;
|
|
|
|
mpool->super.mpool_register = mca_mpool_openib_register;
|
|
|
|
mpool->super.mpool_deregister = mca_mpool_openib_deregister;
|
2005-09-13 02:28:23 +04:00
|
|
|
mpool->super.mpool_find = mca_mpool_openib_find;
|
|
|
|
mpool->super.mpool_retain = mca_mpool_openib_retain;
|
|
|
|
mpool->super.mpool_release = mca_mpool_openib_release;
|
2005-06-21 19:03:59 +04:00
|
|
|
mpool->super.mpool_finalize = NULL;
|
2005-09-13 02:28:23 +04:00
|
|
|
mpool->super.rcache =
|
|
|
|
mca_rcache_base_module_create(mca_mpool_openib_component.rcache_name);
|
2005-09-17 02:22:03 +04:00
|
|
|
mpool->super.flags = MCA_MPOOL_FLAGS_MPI_ALLOC_MEM;
|
2005-05-31 21:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* allocate function
|
|
|
|
*/
|
2005-07-01 01:28:35 +04:00
|
|
|
void* mca_mpool_openib_alloc(
|
2005-06-21 21:10:28 +04:00
|
|
|
mca_mpool_base_module_t* mpool,
|
|
|
|
size_t size,
|
|
|
|
size_t align,
|
2005-09-13 02:28:23 +04:00
|
|
|
uint32_t flags,
|
2005-06-25 01:12:38 +04:00
|
|
|
mca_mpool_base_registration_t** registration)
|
2005-05-31 21:08:41 +04:00
|
|
|
{
|
2005-08-18 21:08:27 +04:00
|
|
|
|
2005-09-27 06:01:21 +04:00
|
|
|
void* addr_malloc = (void*)memalign(mca_mpool_base_page_size, size);
|
2005-07-15 19:13:19 +04:00
|
|
|
void* addr = addr_malloc;
|
|
|
|
|
2005-09-24 04:24:49 +04:00
|
|
|
if(OMPI_SUCCESS != mpool->mpool_register(mpool, addr, size, flags, registration)) {
|
2005-07-15 19:13:19 +04:00
|
|
|
free(addr_malloc);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-07-20 01:04:22 +04:00
|
|
|
(*registration)->alloc_base = addr_malloc;
|
2005-07-15 19:13:19 +04:00
|
|
|
return addr;
|
2005-06-21 19:03:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* register memory
|
|
|
|
*/
|
2005-07-01 01:28:35 +04:00
|
|
|
int mca_mpool_openib_register(mca_mpool_base_module_t* mpool,
|
2005-07-12 17:38:54 +04:00
|
|
|
void *addr,
|
|
|
|
size_t size,
|
2005-09-13 02:28:23 +04:00
|
|
|
uint32_t flags,
|
2005-07-12 17:38:54 +04:00
|
|
|
mca_mpool_base_registration_t** registration){
|
2005-07-15 19:13:19 +04:00
|
|
|
|
2005-07-01 01:28:35 +04:00
|
|
|
mca_mpool_openib_module_t * mpool_module = (mca_mpool_openib_module_t*) mpool;
|
|
|
|
mca_mpool_openib_registration_t * vapi_reg;
|
2005-07-12 17:38:54 +04:00
|
|
|
|
2005-07-01 01:28:35 +04:00
|
|
|
*registration = (mca_mpool_base_registration_t*) OBJ_NEW(mca_mpool_openib_registration_t); /* (void*) malloc(sizeof(mca_mpool_base_registration_t)); */
|
|
|
|
vapi_reg = (mca_mpool_openib_registration_t*) *registration;
|
2005-06-25 01:12:38 +04:00
|
|
|
vapi_reg->base_reg.mpool = mpool;
|
2005-10-20 07:57:17 +04:00
|
|
|
vapi_reg->base_reg.base = down_align_addr(addr, mca_mpool_base_page_size_log);
|
|
|
|
vapi_reg->base_reg.bound = up_align_addr( (void*) ((char*) addr + size - 1)
|
|
|
|
, mca_mpool_base_page_size_log);
|
2005-07-12 17:38:54 +04:00
|
|
|
|
2005-10-20 07:57:17 +04:00
|
|
|
size = vapi_reg->base_reg.bound -vapi_reg->base_reg.base + 1;
|
2005-07-12 17:38:54 +04:00
|
|
|
vapi_reg->mr = ibv_reg_mr(
|
2005-07-13 04:17:08 +04:00
|
|
|
mpool_module->resources.ib_pd,
|
2005-10-20 07:57:17 +04:00
|
|
|
vapi_reg->base_reg.base,
|
2005-07-12 17:38:54 +04:00
|
|
|
size,
|
2005-08-18 21:08:27 +04:00
|
|
|
IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_REMOTE_READ
|
2005-07-15 19:13:19 +04:00
|
|
|
/* IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE */
|
2005-07-12 17:38:54 +04:00
|
|
|
);
|
|
|
|
|
2005-06-25 01:12:38 +04:00
|
|
|
|
2005-07-12 17:38:54 +04:00
|
|
|
if(NULL == vapi_reg->mr){
|
2005-07-15 19:13:19 +04:00
|
|
|
opal_output(0, "%s: error registering openib memory of size %lu errno says %s\n", __func__, size, strerror(errno));
|
2005-06-21 19:03:59 +04:00
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-09-27 22:10:44 +04:00
|
|
|
|
2005-09-13 02:28:23 +04:00
|
|
|
if(flags & (MCA_MPOOL_FLAGS_CACHE | MCA_MPOOL_FLAGS_PERSIST)) {
|
|
|
|
mpool->rcache->rcache_insert(mpool->rcache,
|
|
|
|
(mca_mpool_base_registration_t*) vapi_reg,
|
|
|
|
flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vapi_reg->base_reg.flags = flags;
|
|
|
|
|
|
|
|
mca_mpool_openib_retain(mpool,
|
|
|
|
(mca_mpool_base_registration_t*) vapi_reg);
|
2005-06-21 23:38:50 +04:00
|
|
|
|
2005-09-13 02:28:23 +04:00
|
|
|
|
2005-06-21 19:03:59 +04:00
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* deregister memory
|
|
|
|
*/
|
2005-09-13 02:28:23 +04:00
|
|
|
int mca_mpool_openib_deregister(mca_mpool_base_module_t* mpool,
|
|
|
|
mca_mpool_base_registration_t* registration){
|
2005-06-21 19:03:59 +04:00
|
|
|
|
2005-07-15 19:13:19 +04:00
|
|
|
|
2005-09-13 02:28:23 +04:00
|
|
|
if(registration->flags & (MCA_MPOOL_FLAGS_CACHE | MCA_MPOOL_FLAGS_PERSIST)) {
|
|
|
|
mpool->rcache->rcache_delete(mpool->rcache,
|
|
|
|
registration,
|
|
|
|
registration->flags);
|
2005-10-20 07:57:17 +04:00
|
|
|
registration->flags=0;
|
2005-09-13 02:28:23 +04:00
|
|
|
}
|
|
|
|
|
2005-10-20 07:57:17 +04:00
|
|
|
return mca_mpool_openib_release(mpool, registration);
|
2005-05-31 21:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* realloc function
|
|
|
|
*/
|
2005-07-01 01:28:35 +04:00
|
|
|
void* mca_mpool_openib_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 20:05:05 +04:00
|
|
|
mca_mpool_base_registration_t* old_reg = *registration;
|
2005-09-13 02:28:23 +04:00
|
|
|
void* new_mem = mpool->mpool_alloc(mpool, size, 0,0, registration);
|
2005-07-15 20:05:05 +04:00
|
|
|
memcpy(new_mem, addr, old_reg->bound - old_reg->base);
|
2005-08-18 21:08:27 +04:00
|
|
|
mpool->mpool_free(mpool, addr, old_reg);
|
2005-07-15 20:05:05 +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_openib_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-09-13 02:28:23 +04:00
|
|
|
mpool->mpool_deregister(mpool, registration);
|
2005-07-15 20:05:05 +04:00
|
|
|
free(registration->alloc_base);
|
2005-06-22 01:20:23 +04:00
|
|
|
|
|
|
|
|
2005-05-31 21:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-13 02:28:23 +04:00
|
|
|
int mca_mpool_openib_find(
|
|
|
|
struct mca_mpool_base_module_t* mpool,
|
|
|
|
void* addr,
|
|
|
|
size_t size,
|
|
|
|
ompi_pointer_array_t *regs,
|
|
|
|
uint32_t *cnt
|
|
|
|
){
|
|
|
|
|
|
|
|
return mpool->rcache->rcache_find(mpool->rcache,
|
|
|
|
addr,
|
|
|
|
size,
|
|
|
|
regs,
|
|
|
|
cnt);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int mca_mpool_openib_release(
|
|
|
|
struct mca_mpool_base_module_t* mpool,
|
|
|
|
mca_mpool_base_registration_t* registration
|
|
|
|
){
|
2005-10-20 07:57:17 +04:00
|
|
|
if(0 >= OPAL_THREAD_ADD32(®istration->ref_count, -1)) {
|
|
|
|
mca_mpool_openib_registration_t * openib_reg;
|
|
|
|
openib_reg = (mca_mpool_openib_registration_t*) registration;
|
|
|
|
if(ibv_dereg_mr(openib_reg->mr)){
|
|
|
|
opal_output(0, "%s: error unpinning openib memory errno says %s\n", __func__, strerror(errno));
|
|
|
|
return OMPI_ERROR;
|
|
|
|
}
|
|
|
|
OBJ_RELEASE(openib_reg);
|
2005-09-13 02:28:23 +04:00
|
|
|
}
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mca_mpool_openib_retain(struct mca_mpool_base_module_t* mpool,
|
|
|
|
mca_mpool_base_registration_t* registration
|
|
|
|
){
|
|
|
|
OPAL_THREAD_ADD32(®istration->ref_count, 1);
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-05-31 21:08:41 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-22 01:20:23 +04:00
|
|
|
|
|
|
|
|
2005-05-31 21:08:41 +04:00
|
|
|
|