root/opal/mca/mpool/memkind/mpool_memkind_module.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mca_mpool_memkind_module_init
  2. mca_mpool_memkind_alloc
  3. mca_mpool_memkind_realloc
  4. mca_mpool_memkind_free

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2011 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2005 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2009-2018 Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2011-2018 Los Alamos National Security, LLC. All rights
  15  *                         reserved.
  16  * Copyright (c) 2011-2014 NVIDIA Corporation.  All rights reserved.
  17  * $COPYRIGHT$
  18  *
  19  * Additional copyrights may follow
  20  *
  21  * $HEADER$
  22  */
  23 
  24 #include "opal_config.h"
  25 #include <string.h>
  26 #include "mpool_memkind.h"
  27 #ifdef HAVE_UNISTD_H
  28 #include <unistd.h>
  29 #endif
  30 #include "opal/mca/mpool/base/base.h"
  31 
  32 /*
  33  *  Initializes the mpool module.
  34  */
  35 
  36 void mca_mpool_memkind_module_init(mca_mpool_memkind_module_t *mpool)
  37 {
  38     mpool->super.mpool_component = &mca_mpool_memkind_component.super;
  39     mpool->super.mpool_alloc = mca_mpool_memkind_alloc;
  40     mpool->super.mpool_realloc = mca_mpool_memkind_realloc;
  41     mpool->super.mpool_free = mca_mpool_memkind_free;
  42     mpool->super.flags = MCA_MPOOL_FLAGS_MPI_ALLOC_MEM;
  43 }
  44 
  45 void* mca_mpool_memkind_alloc(
  46     mca_mpool_base_module_t* mpool,
  47     size_t size,
  48     size_t align,
  49     uint32_t flags)
  50 {
  51     mca_mpool_memkind_module_t *memkind_module = (mca_mpool_memkind_module_t *) mpool;
  52     void *addr;
  53 
  54     if (0 == align) {
  55         align = memkind_module->page_size;
  56     }
  57 
  58     if ((errno = memkind_posix_memalign(memkind_module->kind, &addr, align, size))!= 0){
  59         return NULL;
  60     }
  61 
  62     return addr;
  63 }
  64 
  65 void* mca_mpool_memkind_realloc(mca_mpool_base_module_t *mpool, void *addr,
  66                                 size_t size)
  67 {
  68     mca_mpool_memkind_module_t *memkind_module = (mca_mpool_memkind_module_t *) mpool;
  69     return memkind_realloc (memkind_module->kind, addr, size);
  70 }
  71 
  72 void mca_mpool_memkind_free(mca_mpool_base_module_t *mpool, void *addr)
  73 {
  74     mca_mpool_memkind_module_t *memkind_module = (mca_mpool_memkind_module_t *) mpool;
  75     memkind_free(memkind_module->kind, addr);
  76 }

/* [<][>][^][v][top][bottom][index][help] */