2005-06-15 23:10:26 +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>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
#include "opal/threads/mutex.h"
|
2005-06-15 23:10:26 +04:00
|
|
|
#include "datatype/convertor.h"
|
|
|
|
#include "include/sys/atomic.h"
|
2005-07-04 03:31:27 +04:00
|
|
|
#include "opal/util/output.h"
|
2005-06-15 23:10:26 +04:00
|
|
|
#include "util/if.h"
|
|
|
|
#include "util/proc_info.h"
|
|
|
|
#include "util/printf.h"
|
|
|
|
#include "util/sys_info.h"
|
|
|
|
#include "class/ompi_fifo.h"
|
|
|
|
#include "class/ompi_free_list.h"
|
|
|
|
#include "mca/pml/pml.h"
|
2005-06-30 09:50:55 +04:00
|
|
|
#include "mca/btl/btl.h"
|
2005-06-15 23:10:26 +04:00
|
|
|
#include "mca/mpool/base/base.h"
|
2005-06-30 09:50:55 +04:00
|
|
|
#include "btl_self.h"
|
|
|
|
#include "btl_self_frag.h"
|
|
|
|
|
|
|
|
|
|
|
|
mca_btl_base_module_t mca_btl_self = {
|
|
|
|
&mca_btl_self_component.super,
|
|
|
|
0, /* btl_eager_limit */
|
|
|
|
0, /* btl_min_send_size */
|
|
|
|
0, /* btl_max_send_size */
|
|
|
|
0, /* btl_min_rdma_size */
|
|
|
|
0, /* btl_max_rdma_size */
|
|
|
|
0, /* btl_exclusivity */
|
|
|
|
0, /* btl_latency */
|
|
|
|
0, /* btl_bandwidth */
|
|
|
|
0, /* btl flags */
|
|
|
|
mca_btl_self_add_procs,
|
|
|
|
mca_btl_self_del_procs,
|
|
|
|
mca_btl_self_register,
|
|
|
|
mca_btl_self_finalize,
|
|
|
|
mca_btl_self_alloc,
|
|
|
|
mca_btl_self_free,
|
|
|
|
mca_btl_self_prepare_src,
|
|
|
|
mca_btl_self_prepare_dst,
|
|
|
|
mca_btl_self_send,
|
|
|
|
mca_btl_self_rdma, /* put */
|
|
|
|
mca_btl_self_rdma /* get */
|
2005-06-15 23:10:26 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
int mca_btl_self_add_procs(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
2005-06-15 23:10:26 +04:00
|
|
|
size_t nprocs,
|
|
|
|
struct ompi_proc_t **procs,
|
2005-06-30 09:50:55 +04:00
|
|
|
struct mca_btl_base_endpoint_t **peers,
|
2005-06-15 23:10:26 +04:00
|
|
|
ompi_bitmap_t* reachability)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for(i=0; i<nprocs; i++) {
|
2005-06-20 20:38:19 +04:00
|
|
|
if(procs[i] == ompi_proc_local_proc) {
|
|
|
|
ompi_bitmap_set_bit(reachability, i);
|
|
|
|
}
|
2005-06-15 23:10:26 +04:00
|
|
|
}
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
int mca_btl_self_del_procs(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
2005-06-15 23:10:26 +04:00
|
|
|
size_t nprocs,
|
|
|
|
struct ompi_proc_t **procs,
|
2005-06-30 09:50:55 +04:00
|
|
|
struct mca_btl_base_endpoint_t **peers)
|
2005-06-15 23:10:26 +04:00
|
|
|
{
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2005-06-30 09:50:55 +04:00
|
|
|
* MCA->BTL Clean up any resources held by BTL module
|
2005-06-15 23:10:26 +04:00
|
|
|
* before the module is unloaded.
|
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* @param btl (IN) BTL module.
|
2005-06-15 23:10:26 +04:00
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* Prior to unloading a BTL module, the MCA framework will call
|
|
|
|
* the BTL finalize method of the module. Any resources held by
|
|
|
|
* the BTL should be released and if required the memory corresponding
|
|
|
|
* to the BTL module freed.
|
2005-06-15 23:10:26 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
int mca_btl_self_finalize(struct mca_btl_base_module_t* btl)
|
2005-06-15 23:10:26 +04:00
|
|
|
{
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a callback function that is called on receipt
|
|
|
|
* of a fragment.
|
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* @param btl (IN) BTL module
|
2005-06-15 23:10:26 +04:00
|
|
|
* @return Status indicating if cleanup was successful
|
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* When the process list changes, the PML notifies the BTL of the
|
2005-06-15 23:10:26 +04:00
|
|
|
* change, to provide the opportunity to cleanup or release any
|
|
|
|
* resources associated with the peer.
|
|
|
|
*/
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
int mca_btl_self_register(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
|
|
|
mca_btl_base_tag_t tag,
|
|
|
|
mca_btl_base_module_recv_cb_fn_t cbfunc,
|
2005-06-15 23:10:26 +04:00
|
|
|
void* cbdata)
|
|
|
|
{
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_self_component.self_reg[tag].cbfunc = cbfunc;
|
|
|
|
mca_btl_self_component.self_reg[tag].cbdata = cbdata;
|
2005-06-15 23:10:26 +04:00
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate a segment.
|
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* @param btl (IN) BTL module
|
2005-06-15 23:10:26 +04:00
|
|
|
* @param size (IN) Request segment size.
|
|
|
|
*/
|
2005-06-30 09:50:55 +04:00
|
|
|
extern mca_btl_base_descriptor_t* mca_btl_self_alloc(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
2005-06-15 23:10:26 +04:00
|
|
|
size_t size)
|
|
|
|
{
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_self_frag_t* frag;
|
2005-06-15 23:10:26 +04:00
|
|
|
int rc;
|
2005-06-30 09:50:55 +04:00
|
|
|
if(size <= mca_btl_self.btl_eager_limit) {
|
|
|
|
MCA_BTL_SELF_FRAG_ALLOC_EAGER(frag,rc);
|
2005-06-15 23:10:26 +04:00
|
|
|
} else {
|
2005-06-30 09:50:55 +04:00
|
|
|
MCA_BTL_SELF_FRAG_ALLOC_SEND(frag,rc);
|
2005-06-15 23:10:26 +04:00
|
|
|
}
|
|
|
|
frag->base.des_flags = 0;
|
2005-06-30 09:50:55 +04:00
|
|
|
return (mca_btl_base_descriptor_t*)frag;
|
2005-06-15 23:10:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-06-30 09:50:55 +04:00
|
|
|
* Return a segment allocated by this BTL.
|
2005-06-15 23:10:26 +04:00
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* @param btl (IN) BTL module
|
2005-06-15 23:10:26 +04:00
|
|
|
* @param segment (IN) Allocated segment.
|
|
|
|
*/
|
2005-06-30 09:50:55 +04:00
|
|
|
extern int mca_btl_self_free(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
|
|
|
mca_btl_base_descriptor_t* des)
|
2005-06-15 23:10:26 +04:00
|
|
|
{
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_self_frag_t* frag = (mca_btl_self_frag_t*)des;
|
|
|
|
if(frag->size <= mca_btl_self.btl_eager_limit) {
|
|
|
|
MCA_BTL_SELF_FRAG_RETURN_EAGER(frag);
|
|
|
|
} else if (frag->size <= mca_btl_self.btl_max_send_size) {
|
|
|
|
MCA_BTL_SELF_FRAG_RETURN_SEND(frag);
|
2005-06-15 23:10:26 +04:00
|
|
|
} else {
|
2005-06-30 09:50:55 +04:00
|
|
|
MCA_BTL_SELF_FRAG_RETURN_RDMA(frag);
|
2005-06-15 23:10:26 +04:00
|
|
|
}
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare data for send/put
|
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* @param btl (IN) BTL module
|
2005-06-15 23:10:26 +04:00
|
|
|
*/
|
2005-06-30 09:50:55 +04:00
|
|
|
struct mca_btl_base_descriptor_t* mca_btl_self_prepare_src(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
|
|
|
struct mca_btl_base_endpoint_t* endpoint,
|
2005-06-25 01:12:38 +04:00
|
|
|
mca_mpool_base_registration_t* registration,
|
2005-06-15 23:10:26 +04:00
|
|
|
struct ompi_convertor_t* convertor,
|
|
|
|
size_t reserve,
|
|
|
|
size_t* size)
|
|
|
|
{
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_self_frag_t* frag;
|
2005-06-15 23:10:26 +04:00
|
|
|
struct iovec iov;
|
|
|
|
uint32_t iov_count = 1;
|
|
|
|
size_t max_data = *size;
|
|
|
|
int32_t free_after;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* non-contigous data */
|
2005-06-30 09:50:55 +04:00
|
|
|
if(ompi_convertor_need_buffers(convertor) || max_data < mca_btl_self.btl_max_send_size ) {
|
|
|
|
MCA_BTL_SELF_FRAG_ALLOC_SEND(frag, rc);
|
2005-06-15 23:10:26 +04:00
|
|
|
if(NULL == frag) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(reserve + max_data > frag->size) {
|
|
|
|
max_data = frag->size - reserve;
|
|
|
|
}
|
|
|
|
iov.iov_len = max_data;
|
2005-06-21 21:37:49 +04:00
|
|
|
iov.iov_base = (void*)((unsigned char*)(frag+1) + reserve);
|
2005-06-15 23:10:26 +04:00
|
|
|
|
|
|
|
rc = ompi_convertor_pack(convertor, &iov, &iov_count, &max_data, &free_after);
|
|
|
|
if(rc < 0) {
|
2005-06-30 09:50:55 +04:00
|
|
|
MCA_BTL_SELF_FRAG_RETURN_SEND(frag);
|
2005-06-15 23:10:26 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
frag->base.des_flags = 0;
|
|
|
|
frag->segment.seg_addr.pval = frag+1;
|
|
|
|
frag->segment.seg_len = reserve + max_data;
|
|
|
|
*size = max_data;
|
|
|
|
} else {
|
2005-06-30 09:50:55 +04:00
|
|
|
MCA_BTL_SELF_FRAG_ALLOC_RDMA(frag, rc);
|
2005-06-15 23:10:26 +04:00
|
|
|
if(NULL == frag) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
iov.iov_len = max_data;
|
|
|
|
iov.iov_base = NULL;
|
|
|
|
|
|
|
|
/* convertor should return offset into users buffer */
|
|
|
|
rc = ompi_convertor_pack(convertor, &iov, &iov_count, &max_data, &free_after);
|
|
|
|
if(rc < 0) {
|
2005-06-30 09:50:55 +04:00
|
|
|
MCA_BTL_SELF_FRAG_RETURN_RDMA(frag);
|
2005-06-15 23:10:26 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
frag->segment.seg_addr.pval = iov.iov_base;
|
|
|
|
frag->segment.seg_len = reserve + max_data;
|
2005-06-20 20:38:19 +04:00
|
|
|
frag->base.des_src = &frag->segment;
|
|
|
|
frag->base.des_src_cnt = 1;
|
|
|
|
frag->base.des_dst = NULL;
|
|
|
|
frag->base.des_dst_cnt = 0;
|
|
|
|
frag->base.des_flags = 0;
|
2005-06-15 23:10:26 +04:00
|
|
|
*size = max_data;
|
|
|
|
}
|
|
|
|
return &frag->base;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare data for receive.
|
|
|
|
*/
|
2005-06-30 09:50:55 +04:00
|
|
|
struct mca_btl_base_descriptor_t* mca_btl_self_prepare_dst(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
|
|
|
struct mca_btl_base_endpoint_t* endpoint,
|
2005-06-25 01:12:38 +04:00
|
|
|
mca_mpool_base_registration_t* registration,
|
2005-06-15 23:10:26 +04:00
|
|
|
struct ompi_convertor_t* convertor,
|
|
|
|
size_t reserve,
|
|
|
|
size_t* size)
|
|
|
|
{
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_self_frag_t* frag;
|
2005-06-15 23:10:26 +04:00
|
|
|
size_t max_data = *size;
|
|
|
|
int rc;
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
MCA_BTL_SELF_FRAG_ALLOC_RDMA(frag, rc);
|
2005-06-15 23:10:26 +04:00
|
|
|
if(NULL == frag) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* setup descriptor to point directly to user buffer */
|
|
|
|
frag->segment.seg_addr.pval = (unsigned char*)convertor->pBaseBuf + convertor->bConverted;
|
|
|
|
frag->segment.seg_len = reserve + max_data;
|
2005-06-20 20:38:19 +04:00
|
|
|
frag->base.des_src = NULL;
|
|
|
|
frag->base.des_src_cnt = 0;
|
|
|
|
frag->base.des_dst = &frag->segment;
|
|
|
|
frag->base.des_dst_cnt = 1;
|
|
|
|
frag->base.des_flags = 0;
|
2005-06-15 23:10:26 +04:00
|
|
|
return &frag->base;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initiate a send to the peer.
|
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* @param btl (IN) BTL module
|
|
|
|
* @param peer (IN) BTL peer addressing
|
2005-06-15 23:10:26 +04:00
|
|
|
*/
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
int mca_btl_self_send(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
|
|
|
struct mca_btl_base_endpoint_t* endpoint,
|
|
|
|
struct mca_btl_base_descriptor_t* des,
|
|
|
|
mca_btl_base_tag_t tag)
|
2005-06-15 23:10:26 +04:00
|
|
|
{
|
2005-06-20 20:38:19 +04:00
|
|
|
/* upcall */
|
2005-06-20 18:58:20 +04:00
|
|
|
des->des_dst = des->des_src;
|
|
|
|
des->des_dst_cnt = des->des_src_cnt;
|
|
|
|
des->des_src = NULL;
|
|
|
|
des->des_src_cnt = 0;
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_self_component.self_reg[tag].cbfunc(btl,tag,des,OMPI_SUCCESS);
|
2005-06-20 18:58:20 +04:00
|
|
|
des->des_src = des->des_dst;
|
|
|
|
des->des_src_cnt = des->des_dst_cnt;
|
|
|
|
des->des_dst = NULL;
|
|
|
|
des->des_dst_cnt = 0;
|
2005-06-20 20:38:19 +04:00
|
|
|
|
|
|
|
/* send completion */
|
2005-06-30 09:50:55 +04:00
|
|
|
des->des_cbfunc(btl,endpoint,des,OMPI_SUCCESS);
|
2005-06-20 20:38:19 +04:00
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initiate a put to the peer.
|
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* @param btl (IN) BTL module
|
|
|
|
* @param peer (IN) BTL peer addressing
|
2005-06-20 20:38:19 +04:00
|
|
|
*/
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
extern int mca_btl_self_rdma(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
|
|
|
struct mca_btl_base_endpoint_t* endpoint,
|
|
|
|
struct mca_btl_base_descriptor_t* des)
|
2005-06-20 20:38:19 +04:00
|
|
|
{
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_base_segment_t* src = des->des_src;
|
|
|
|
mca_btl_base_segment_t* dst = des->des_dst;
|
2005-06-20 20:38:19 +04:00
|
|
|
size_t src_cnt = des->des_src_cnt;
|
|
|
|
size_t dst_cnt = des->des_dst_cnt;
|
|
|
|
unsigned char* src_addr = dst->seg_addr.pval;
|
|
|
|
size_t src_len = src->seg_len;
|
|
|
|
unsigned char* dst_addr = dst->seg_addr.pval;
|
|
|
|
size_t dst_len = dst->seg_len;
|
|
|
|
|
|
|
|
while(src_len && dst_len) {
|
|
|
|
|
|
|
|
if(src_len == dst_len) {
|
|
|
|
memcpy(dst_addr, src_addr, src_len);
|
|
|
|
|
|
|
|
/* advance src */
|
|
|
|
if(--src_cnt != 0) {
|
|
|
|
src++;
|
|
|
|
src_addr = src->seg_addr.pval;
|
|
|
|
src_len = src->seg_len;
|
|
|
|
} else {
|
|
|
|
src_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* advance dst */
|
|
|
|
if(--dst_cnt != 0) {
|
|
|
|
dst++;
|
|
|
|
dst_addr = dst->seg_addr.pval;
|
|
|
|
dst_len = dst->seg_len;
|
|
|
|
} else {
|
|
|
|
dst_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
size_t bytes = src_len < dst_len ? src_len : dst_len;
|
|
|
|
memcpy(dst_addr, src_addr, bytes);
|
|
|
|
|
|
|
|
/* advance src */
|
|
|
|
src_len -= bytes;
|
|
|
|
if(src_len == 0) {
|
|
|
|
if(--src_cnt != 0) {
|
|
|
|
src++;
|
|
|
|
src_addr = src->seg_addr.pval;
|
|
|
|
src_len = src->seg_len;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
src_addr += bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* advance dst */
|
|
|
|
dst_len -= bytes;
|
|
|
|
if(dst_len == 0) {
|
|
|
|
if(--dst_cnt != 0) {
|
|
|
|
dst++;
|
|
|
|
dst_addr = src->seg_addr.pval;
|
|
|
|
dst_len = src->seg_len;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dst_addr += bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* rdma completion */
|
2005-06-30 09:50:55 +04:00
|
|
|
des->des_cbfunc(btl,endpoint,des,OMPI_SUCCESS);
|
2005-06-15 23:10:26 +04:00
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|