Exemplo n.º 1
0
TEST_F(MemkindPmemTests, test_TC_MEMKIND_PmemCalloc)
{
    const size_t size = 1024;
    const size_t num = 1;
    char *default_str = NULL;

    default_str = (char *)memkind_calloc(pmem_kind, num, size);
    EXPECT_TRUE(NULL != default_str);
    EXPECT_EQ(*default_str, 0);

    sprintf(default_str, "memkind_calloc MEMKIND_PMEM\n");
    printf("%s", default_str);

    memkind_free(pmem_kind, default_str);

    // allocate the buffer of the same size (likely at the same address)
    default_str = (char *)memkind_calloc(pmem_kind, num, size);
    EXPECT_TRUE(NULL != default_str);
    EXPECT_EQ(*default_str, 0);

    sprintf(default_str, "memkind_calloc MEMKIND_PMEM\n");
    printf("%s", default_str);

    memkind_free(pmem_kind, default_str);
}
Exemplo n.º 2
0
////////////////////////////////////////////////////////////////////////////
// My memkind free function calling memkind_free (with Kind=0).
// Note: memkind_free does not need the exact kind, if kind is 0. Then
//       the library can figure out the proper kind itself.
////////////////////////////////////////////////////////////////////////////
void myMemkindFree(void *ptr)
{

    DBG(2) printf("In my memkind free, ptr:%p\n", ptr);

    memkind_free(0, ptr);
}
Exemplo n.º 3
0
void test_allocation(memkind_t kind, size_t size)
{
    ASSERT_TRUE(kind != NULL);
    void* ptr = memkind_malloc(kind, size);
    ASSERT_TRUE(ptr != NULL);
    void* memset_ret = memset(ptr, 3, size);
    ASSERT_TRUE(memset_ret != NULL);
    memkind_free(kind, ptr);
}
Exemplo n.º 4
0
void HBWSpace::deallocate( void * const arg_alloc_ptr , const size_t arg_alloc_size ) const
{
  if ( arg_alloc_ptr ) {

    if ( m_alloc_mech == STD_MALLOC ) {
      void * alloc_ptr = *(reinterpret_cast<void **>(arg_alloc_ptr) -1);
      memkind_free(MEMKIND_TYPE, alloc_ptr );
    }    

  }
}
TEST_F(FreeingMemorySegfault, test_TC_MEMKIND_freeing_memory_after_thread_finish)
{
    void* ptr = nullptr;

    std::thread t([&] {
        ptr = memkind_malloc(MEMKIND_DEFAULT, 32);
        ASSERT_TRUE(ptr != NULL);
    });
    t.join();

    memkind_free(0, ptr);
    SUCCEED();
}
TEST_F(MemkindDefaultTests, test_TC_MEMKIND_DefaultCalloc)
{
    const size_t size = 1024;
    const size_t num = 1;
    char *default_str = NULL;

    default_str = (char *)memkind_calloc(MEMKIND_DEFAULT, num, size);
    EXPECT_TRUE(NULL != default_str);

    sprintf(default_str, "memkind_calloc MEMKIND_DEFAULT\n");
    printf("%s", default_str);

    memkind_free(MEMKIND_DEFAULT, default_str);
}
Exemplo n.º 7
0
static void remove_info_entry_from_state(struct distmem *dist_kind, void *ptr) {
  int hash_key = get_hashkey(ptr);
  struct distmem_memory_information_generic *specific_state = dist_kind->internal_state[hash_key], *last_entry = NULL;
  while (specific_state != NULL) {
    if (specific_state->ptr == ptr) {
      if (last_entry == NULL) {
        dist_kind->internal_state[hash_key] = specific_state->next;
      } else {
        last_entry->next = specific_state->next;
      }
      if (specific_state->deallocate_specific_information != NULL) {
        specific_state->deallocate_specific_information(specific_state->specific_information);
      } else {
        if (specific_state->specific_information != NULL) {
          memkind_free(MEMKIND_DEFAULT, specific_state->specific_information);
        }
      }
      memkind_free(MEMKIND_DEFAULT, specific_state);
      break;
    }
    last_entry = specific_state;
    specific_state = specific_state->next;
  }
}
Exemplo n.º 8
0
////////////////////////////////////////////////////////////////////////////
// This function is executed at library load time.
// Initilize HBW arena by making a dummy allocation/free at library load
// time. Until HBW initialization is complete, we must not call any
// allocation routines with HBW as kind.
////////////////////////////////////////////////////////////////////////////
void __attribute__ ((constructor)) autohbw_load(void)
{

    // First set the default memory type this library allocates. This can
    // be overridden by env variable
    // Note: 'memkind_hbw_preferred' will allow falling back to DDR but
    //       'memkind_hbw will not'
    // Note: If HBM is not installed on a system, memkind_hbw_preferred call
    //       woudl fail. Therefore, we need to check for availability first.
    //
    int ret = 0;
    if (memkind_check_available(MEMKIND_HBW) == 0) {
      ret = memkind_get_kind_by_name("memkind_hbw_preferred", &HBW_Type);
    }
    else {
      printf("WARN: *** No HBM found in system. Will use default (DDR) "
             "OR user specifid type ***\n");
      ret = memkind_get_kind_by_name("memkind_default", &HBW_Type);
    }
    assert(!ret && "FATAL: Could not find default memory type\n");

    // Read any env variables. This has to be done first because DbgLevel
    // is set using env variables and debug printing is used below
    //
    setEnvValues();                // read any env variables

    DBG(1) printf("INFO: autohbw.so loaded!\n");

    // dummy HBW call to initialize HBW arena
    //
    void *pp = memkind_malloc(HBW_Type, 16);
    //
    if (pp) {

        // We have successfully initilized HBW arena
        //
        DBG(2) printf("\t-HBW int call succeeded\n");
        memkind_free(0, pp);

        MemkindInitDone = TRUE;        // enable HBW allocation

    }
    else {
        errPrn("\t-HBW init call FAILED. Is required memory type present on your system?\n");
        assert(0 && "HBW/memkind initialization faild");
    }
}
Exemplo n.º 9
0
TEST_F(MemkindPmemTests, test_TC_MEMKIND_PmemMalloc)
{
    const size_t size = 1024;
    char *default_str = NULL;

    default_str = (char *)memkind_malloc(pmem_kind, size);
    EXPECT_TRUE(NULL != default_str);

    sprintf(default_str, "memkind_malloc MEMKIND_PMEM\n");
    printf("%s", default_str);

    memkind_free(pmem_kind, default_str);

    // Out of memory
    default_str = (char *)memkind_malloc(pmem_kind, 2 * PMEM_PART_SIZE);
    EXPECT_EQ(NULL, default_str);
}
Exemplo n.º 10
0
int main(int argc, char *argv[]) {
    MPI_Init(&argc, &argv);
    int myrank;
    MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
    distmem_mpi_init();
    int * buffer=(int*) distmem_mpi_malloc(MPI_CONTIGUOUS_KIND, 4, 17, MPI_COMM_WORLD);
    struct distmem_mpi_memory_information * alloc_info=distmem_mpi_get_info(MPI_CONTIGUOUS_KIND, buffer);
    printf("Total number elements=%zu, distributed over %d procs, local number elements=%zu\n", alloc_info->total_number_elements,
           alloc_info->procs_distributed_over, alloc_info->number_local_elements);
    int i;
    for (i=0; i<alloc_info->number_local_elements; i++) {
        buffer[i]=i*(myrank+1);
    }
    memkind_free(MPI_CONTIGUOUS_KIND, buffer);
    MPI_Finalize();
    return 0;
}
Exemplo n.º 11
0
TEST_F(MemkindDefaultTests, test_TC_MEMKIND_DefaultGetSize)
{
    const size_t size = 512;
    char *default_str = NULL;
    int err = 0;
    size_t *total, *free;
    total = (size_t*) malloc(sizeof(size_t));
    free = (size_t*) malloc(sizeof(size_t));

    default_str = (char *)memkind_malloc(MEMKIND_DEFAULT, size);
    EXPECT_TRUE(NULL != default_str);

    err = memkind_get_size(MEMKIND_DEFAULT, total, free);

    EXPECT_EQ(0,err);

    memkind_free(MEMKIND_DEFAULT, default_str);
}
Exemplo n.º 12
0
TEST_F(MemkindPmemTests, PmemGetSize)
{
    const size_t size = 512;
    char *default_str = NULL;
    int err = 0;
    size_t total;
    size_t free;

    default_str = (char *)memkind_malloc(pmem_kind, size);
    EXPECT_TRUE(NULL != default_str);

    err = memkind_get_size(pmem_kind, &total, &free);
    EXPECT_EQ(0, err);

    // requested PMEM partition size is internally aligned to 4MB
    EXPECT_EQ(total, (size_t)roundup(PMEM_PART_SIZE, CHUNK_SIZE));

    memkind_free(pmem_kind, default_str);
}
Exemplo n.º 13
0
TEST_F(MemkindPmemTests, test_TC_MEMKIND_PmemRealloc)
{
    const size_t size1 = 512;
    const size_t size2 = 1024;
    char *default_str = NULL;

    default_str = (char *)memkind_realloc(pmem_kind, default_str, size1);
    EXPECT_TRUE(NULL != default_str);

    sprintf(default_str, "memkind_realloc MEMKIND_PMEM with size %zu\n", size1);
    printf("%s", default_str);

    default_str = (char *)memkind_realloc(pmem_kind, default_str, size2);
    EXPECT_TRUE(NULL != default_str);

    sprintf(default_str, "memkind_realloc MEMKIND_PMEM with size %zu\n", size2);
    printf("%s", default_str);

    memkind_free(pmem_kind, default_str);
}
Exemplo n.º 14
0
TEST_F(MemkindDefaultTests, test_TC_MEMKIND_DefaultRealloc)
{
    const size_t size1 = 512;
    const size_t size2 = 1024;
    char *default_str = NULL;

    default_str = (char *)memkind_realloc(MEMKIND_DEFAULT, default_str, size1);
    EXPECT_TRUE(NULL != default_str);

    sprintf(default_str, "memkind_realloc MEMKIND_DEFAULT with size %zu\n", size1);
    printf("%s", default_str);

    default_str = (char *)memkind_realloc(MEMKIND_DEFAULT, default_str, size2);
    EXPECT_TRUE(NULL != default_str);

    sprintf(default_str, "memkind_realloc MEMKIND_DEFAULT with size %zu\n", size2);
    printf("%s", default_str);

    memkind_free(MEMKIND_DEFAULT, default_str);
}
Exemplo n.º 15
0
void *memkind_arena_realloc(struct memkind *kind, void *ptr, size_t size)
{
    int err = 0;
    unsigned int arena;

    if (size == 0 && ptr != NULL) {
        memkind_free(kind, ptr);
        ptr = NULL;
    }
    else {
        err = kind->ops->get_arena(kind, &arena, size);
        if (!err) {
            if (ptr == NULL) {
                ptr = jemk_mallocx_check(size, MALLOCX_ARENA(arena));
            }
            else {
                ptr = jemk_rallocx_check(ptr, size, MALLOCX_ARENA(arena));
            }
        }
    }
    return ptr;
}
Exemplo n.º 16
0
int
main(int argc, char **argv)
    {
    int			quantum, checktick();
    int			BytesPerWord;
    int			k;
    ssize_t		j;
    STREAM_TYPE		scalar;
    double		t, times[4][NTIMES];
#ifdef ENABLE_DYNAMIC_ALLOC
    int	err = 0;
    memkind_t kind;
    char err_msg[ERR_MSG_SIZE];
    if (argc > 1 && (strncmp("--help", argv[1], strlen("--help")) == 0 ||
                     strncmp("-h", argv[1], strlen("-h")) == 0)) {
        printf("Usage: %s [memkind_default | memkind_hbw | memkind_hbw_hugetlb | \n" 
               "    memkind_hbw_preferred | memkind_hbw_preferred_hugetlb | \n"
               "    memkind_hbw_gbtlb | memkind_hbw_preferred_gbtlb | memkind_gbtlb | \n"
               "    memkind_hbw_interleave | memkind_interleave]\n",
               argv[0]);
        return 0;
    }
#endif

    /* --- SETUP --- determine precision and check timing --- */

    printf(HLINE);
    printf("STREAM version $Revision: 5.10 $\n");
#ifdef ENABLE_DYNAMIC_ALLOC
    printf("Variant that uses the memkind library for dynamic memory allocation.\n");
#endif
    printf(HLINE);
    BytesPerWord = sizeof(STREAM_TYPE);
    printf("This system uses %d bytes per array element.\n",
	BytesPerWord);

    printf(HLINE);
#ifdef N
    printf("*****  WARNING: ******\n");
    printf("      It appears that you set the preprocessor variable N when compiling this code.\n");
    printf("      This version of the code uses the preprocesor variable STREAM_ARRAY_SIZE to control the array size\n");
    printf("      Reverting to default value of STREAM_ARRAY_SIZE=%llu\n",(unsigned long long) STREAM_ARRAY_SIZE);
    printf("*****  WARNING: ******\n");
#endif

    printf("Array size = %llu (elements), Offset = %d (elements)\n" , (unsigned long long) STREAM_ARRAY_SIZE, OFFSET);
    printf("Memory per array = %.1f MiB (= %.1f GiB).\n", 
	BytesPerWord * ( (double) STREAM_ARRAY_SIZE / 1024.0/1024.0),
	BytesPerWord * ( (double) STREAM_ARRAY_SIZE / 1024.0/1024.0/1024.0));
    printf("Total memory required = %.1f MiB (= %.1f GiB).\n",
	(3.0 * BytesPerWord) * ( (double) STREAM_ARRAY_SIZE / 1024.0/1024.),
	(3.0 * BytesPerWord) * ( (double) STREAM_ARRAY_SIZE / 1024.0/1024./1024.));
    printf("Each kernel will be executed %d times.\n", NTIMES);
    printf(" The *best* time for each kernel (excluding the first iteration)\n"); 
    printf(" will be used to compute the reported bandwidth.\n");

#ifdef _OPENMP
    printf(HLINE);
#pragma omp parallel 
    {
#pragma omp master
	{
	    k = omp_get_num_threads();
	    printf ("Number of Threads requested = %i\n",k);
        }
    }
#endif

#ifdef _OPENMP
	k = 0;
#pragma omp parallel
#pragma omp atomic 
		k++;
    printf ("Number of Threads counted = %i\n",k);
#endif

#ifdef ENABLE_DYNAMIC_ALLOC
    if (argc > 1) {
        err = memkind_get_kind_by_name(argv[1], &kind);
    }
    else {
        err = memkind_get_kind_by_name("memkind_default", &kind);
    }
    if (err) {
        memkind_error_message(err, err_msg, ERR_MSG_SIZE);
        fprintf(stderr, "ERROR: %s\n", err_msg);
        return -1;
    }
    err = memkind_posix_memalign(kind, (void **)&a, 2097152, BytesPerWord * (STREAM_ARRAY_SIZE + OFFSET));
    if (err) {
        fprintf(stderr, "ERROR: Unable to allocate stream array a\n");
        return -err;
    }
    err = memkind_posix_memalign(kind, (void **)&b, 2097152, BytesPerWord * (STREAM_ARRAY_SIZE + OFFSET));
    if (err) {
        fprintf(stderr, "ERROR: Unable to allocate stream array b\n");
        return -err;
    }
    err = memkind_posix_memalign(kind, (void **)&c, 2097152, BytesPerWord * (STREAM_ARRAY_SIZE + OFFSET));
    if (err) {
        fprintf(stderr, "ERROR: Unable to allocate stream array c\n");
        return -err;
    }

#endif
    /* Get initial value for system clock. */
#pragma omp parallel for
    for (j=0; j<STREAM_ARRAY_SIZE; j++) {
	    a[j] = 1.0;
	    b[j] = 2.0;
	    c[j] = 0.0;
	}

    printf(HLINE);

    if  ( (quantum = checktick()) >= 1) 
	printf("Your clock granularity/precision appears to be "
	    "%d microseconds.\n", quantum);
    else {
	printf("Your clock granularity appears to be "
	    "less than one microsecond.\n");
	quantum = 1;
    }

    t = mysecond();
#pragma omp parallel for
    for (j = 0; j < STREAM_ARRAY_SIZE; j++)
		a[j] = 2.0E0 * a[j];
    t = 1.0E6 * (mysecond() - t);

    printf("Each test below will take on the order"
	" of %d microseconds.\n", (int) t  );
    printf("   (= %d clock ticks)\n", (int) (t/quantum) );
    printf("Increase the size of the arrays if this shows that\n");
    printf("you are not getting at least 20 clock ticks per test.\n");

    printf(HLINE);

    printf("WARNING -- The above is only a rough guideline.\n");
    printf("For best results, please be sure you know the\n");
    printf("precision of your system timer.\n");
    printf(HLINE);
    
    /*	--- MAIN LOOP --- repeat test cases NTIMES times --- */

    scalar = 3.0;
    for (k=0; k<NTIMES; k++)
	{
	times[0][k] = mysecond();
#ifdef TUNED
        tuned_STREAM_Copy();
#else
#pragma omp parallel for
	for (j=0; j<STREAM_ARRAY_SIZE; j++)
	    c[j] = a[j];
#endif
	times[0][k] = mysecond() - times[0][k];
	
	times[1][k] = mysecond();
#ifdef TUNED
        tuned_STREAM_Scale(scalar);
#else
#pragma omp parallel for
	for (j=0; j<STREAM_ARRAY_SIZE; j++)
	    b[j] = scalar*c[j];
#endif
	times[1][k] = mysecond() - times[1][k];
	
	times[2][k] = mysecond();
#ifdef TUNED
        tuned_STREAM_Add();
#else
#pragma omp parallel for
	for (j=0; j<STREAM_ARRAY_SIZE; j++)
	    c[j] = a[j]+b[j];
#endif
	times[2][k] = mysecond() - times[2][k];
	
	times[3][k] = mysecond();
#ifdef TUNED
        tuned_STREAM_Triad(scalar);
#else
#pragma omp parallel for
	for (j=0; j<STREAM_ARRAY_SIZE; j++)
	    a[j] = b[j]+scalar*c[j];
#endif
	times[3][k] = mysecond() - times[3][k];
	}

    /*	--- SUMMARY --- */

    for (k=1; k<NTIMES; k++) /* note -- skip first iteration */
	{
	for (j=0; j<4; j++)
	    {
	    avgtime[j] = avgtime[j] + times[j][k];
	    mintime[j] = MIN(mintime[j], times[j][k]);
	    maxtime[j] = MAX(maxtime[j], times[j][k]);
	    }
	}
    
    printf("Function    Best Rate MB/s  Avg time     Min time     Max time\n");
    for (j=0; j<4; j++) {
		avgtime[j] = avgtime[j]/(double)(NTIMES-1);

		printf("%s%12.1f  %11.6f  %11.6f  %11.6f\n", label[j],
	       1.0E-06 * bytes[j]/mintime[j],
	       avgtime[j],
	       mintime[j],
	       maxtime[j]);
    }
    printf(HLINE);

    /* --- Check Results --- */
    checkSTREAMresults();
    printf(HLINE);

#ifdef ENABLE_DYNAMIC_ALLOC
    memkind_free(kind, c);
    memkind_free(kind, b);
    memkind_free(kind, a);
#endif
    return 0;
}
Exemplo n.º 17
0
 void mk_free(void* ptr) 
 {
   assert(ptr);
   memkind_free(MEMKIND_DEFAULT,ptr);
 }
Exemplo n.º 18
0
void mca_mpool_memkind_free(mca_mpool_base_module_t *mpool, void *addr)
{
    mca_mpool_memkind_module_t *memkind_module = (mca_mpool_memkind_module_t *) mpool;
    memkind_free(memkind_module->kind, addr);
}
Exemplo n.º 19
0
void hbw_free(void *ptr)
{
    memkind_free(0, ptr);
}
Exemplo n.º 20
0
int main(int argc, char *argv[])
{
    struct memkind *pmem_kind_unlimited = NULL;
    int err = 0;

    if (argc > 2) {
        fprintf(stderr, "Usage: %s [pmem_kind_dir_path]\n", argv[0]);
        return 1;
    } else if (argc == 2 && (realpath(argv[1], path) == NULL)) {
        fprintf(stderr, "Incorrect pmem_kind_dir_path %s\n", argv[1]);
        return 1;
    }

    fprintf(stdout,
            "This example shows how to use multithreading with one main pmem kind."
            "\nPMEM kind directory: %s\n", path);

    // Create PMEM partition with unlimited size
    err = memkind_create_pmem(path, 0, &pmem_kind_unlimited);
    if (err) {
        print_err_message(err);
        return 1;
    }

    // Create a few threads which will access to our main pmem_kind
    pthread_t pmem_threads[NUM_THREADS];
    int *pmem_tint[NUM_THREADS][NUM_ALLOCS];
    int t = 0, i = 0;

    struct arg_struct *args[NUM_THREADS];

    for (t = 0; t<NUM_THREADS; t++) {
        args[t] = malloc(sizeof(struct arg_struct));
        args[t]->id = t;
        args[t]->ptr = &pmem_tint[t][0];
        args[t]->kind = pmem_kind_unlimited;

        if (pthread_create(&pmem_threads[t], NULL, thread_onekind,
                           (void *)args[t])!= 0) {
            fprintf(stderr, "Unable to create a thread.\n");
            return 1;
        }
    }

    sleep(1);
    if (pthread_cond_broadcast(&cond) != 0) {
        fprintf(stderr, "Unable to broadcast a condition.\n");
        return 1;
    }

    for (t = 0; t < NUM_THREADS; t++) {
        if (pthread_join(pmem_threads[t], NULL) != 0) {
            fprintf(stderr, "Thread join failed.\n");
            return 1;
        }
    }

    // Check if we can read the values outside of threads and free resources
    for (t = 0; t < NUM_THREADS; t++) {
        for (i = 0; i < NUM_ALLOCS; i++) {
            if(*pmem_tint[t][i] != t) {
                fprintf(stderr,
                        "pmem_tint value has not been saved correctly in the thread.\n");
                return 1;
            }
            memkind_free(args[t]->kind, *(args[t]->ptr+i));
        }
        free(args[t]);
    }

    fprintf(stdout, "Threads successfully allocated memory in the PMEM kind.\n");

    return 0;
}
Exemplo n.º 21
0
MEMKIND_EXPORT void hbw_free(void *ptr)
{
    memkind_free(0, ptr);
}
Exemplo n.º 22
0
void distmem_free(struct memkind *kind, void *ptr) {
  remove_info_entry_from_state(distmem_get_distkind_by_name(kind->name), ptr);
  memkind_free(MEMKIND_DEFAULT, ptr);
}
	void wrapped_free(void* ptr) {memkind_free(kind, ptr);}