コード例 #1
0
int main(int argc, char * argv[])
{
    size_t bytes = (argc>1) ? atol(argv[1]) : 1024*1024;

    int avail = hbw_check_available();
    printf("%s returned %s\n", "hbw_check_available", avail==0 ? "SUCCESS" : "FAILURE");
    assert(avail == 0);

    void * a = hbw_malloc(bytes);
    assert(a != NULL);
    hbw_free(a);

    void * b = hbw_calloc(bytes, 1);
    assert(b != NULL);
    hbw_free(b);

    void * c = hbw_realloc(NULL, bytes);
    printf("hbw_realloc c=%p\n", c);
    assert(c != NULL);

    void * d = hbw_realloc(c, 0);
    printf("hbw_realloc c=%p d=%p\n", c, d);

    void * e = NULL;
    int rc = hbw_posix_memalign(&e, 4096, bytes);
    printf("hbw_posix_memalign rc=%d e=%p\n", rc, e);
    assert(rc == 0 && e != NULL);

    return 0;
}
コード例 #2
0
int main(int argc, char **argv)
{
    const size_t size = 512;
    char *default_str = NULL;
    char *hbw_str = NULL;
    char *hbw_hugetlb_str = NULL;
    int err = 0;

    default_str = (char *)malloc(size);
    if (default_str == NULL) {
        perror("malloc()");
        fprintf(stderr, "Unable to allocate default string\n");
        err = errno ? -errno : 1;
        goto exit;
    }
    hbw_str = (char *)hbw_malloc(size);
    if (hbw_str == NULL) {
        perror("hbw_malloc()");
        fprintf(stderr, "Unable to allocate hbw string\n");
        err = errno ? -errno : 1;
        goto exit;
    }
    err = hbw_posix_memalign_psize((void **)&hbw_hugetlb_str, 2097152, size, HBW_PAGESIZE_2MB);
    if (err) {
        perror("hbw_posix_memalign()");
        fprintf(stderr, "Unable to allocate hbw hugetlb string\n");
        err = errno ? -errno : 1;
        goto exit;
    }

    sprintf(default_str, "Hello world from standard memory\n");
    sprintf(hbw_str, "Hello world from high bandwidth memory\n");
    sprintf(hbw_hugetlb_str, "Hello world from high bandwidth 2 MB paged memory\n");

    fprintf(stdout, "%s", default_str);
    fprintf(stdout, "%s", hbw_str);
    fprintf(stdout, "%s", hbw_hugetlb_str);

exit:
    if (hbw_hugetlb_str) {
        hbw_free(hbw_hugetlb_str);
    }
    if (hbw_str) {
        hbw_free(hbw_str);
    }
    if (default_str) {
        free(default_str);
    }
    return err;
}
コード例 #3
0
ファイル: mhbw.c プロジェクト: firedrakeproject/petsc
static PetscErrorCode PetscHBWFree(void *aa,int lineno,const char function[],const char filename[])
{
#if !defined(PETSC_HAVE_MEMKIND)
  return PetscFreeAlign(aa,lineno,function,filename);
#else
  hbw_free(aa);
  return 0;
#endif
}
コード例 #4
0
ファイル: MemoryAllocator.cpp プロジェクト: jjww2015/SeisSol
void seissol::memory::free(void* i_pointer, enum Memkind i_memkind)
{
#ifdef USE_MEMKIND
    if (i_memkind == Standard) {
#endif
      ::free( i_pointer );
#ifdef USE_MEMKIND
    } else {
      hbw_free( i_pointer );
    }
#endif
}
コード例 #5
0
int main (int argc, char *argv[])
{
    void *ptr;
    int err = 0;

    hbw_set_policy(HBW_POLICY_BIND);

    printf ("Allocating 400 KB with 1GB pages\n");
    err = hbw_posix_memalign_psize (&ptr,
                                    1073741824,
                                    409600,
                                    HBW_PAGESIZE_1GB);

    if (err) {
        fprintf(stderr, "ERROR: hbw_posix_memalign_size()\n");
    }
    if (!err) {
        memset (ptr, 0, 409600);
        printf ("Reallocing 100KB with 1GB pages\n");
        ptr = hbw_realloc (ptr, 102400);
        if (ptr == NULL) {
            fprintf(stderr, "ERROR: hbw_realloc()\n");
            err = -1;
        }
    }
    if (!err) {
        memset (ptr, 0, 102400);
        printf ("Reallocing 1GB with 1GB pages\n");
        ptr = hbw_realloc (ptr, 1073741824);
        if (ptr == NULL) {
            fprintf(stderr, "ERROR: hbw_realloc()");
            err = -1;
        }
    }
    if (!err) {
        memset (ptr, 0, 1073741824);
        printf ("Reallocing 1073742848 with 1GB pages\n");
        ptr = hbw_realloc (ptr, 1073742848);
        if (ptr == NULL) {
            fprintf(stderr, "ERROR:  hbw_realloc()\n");
            err = -1;
        }
    }
    if (!err) {
        memset (ptr, 0, 1073742848);
    }
    if (ptr) {
        hbw_free(ptr);
    }

    return err;
}
コード例 #6
0
/* This test is run with overridden MEMKIND_HBW_NODES environment variable
 * and tries to perform allocation from DRAM using hbw_malloc() using
 * default HBW_POLICY_PREFERRED policy.
 */
int main()
{
    struct bitmask *expected_nodemask = NULL;
    struct bitmask *returned_nodemask = NULL;
    void *ptr = NULL;
    int ret = 0;
    int status = 0;

    ptr = hbw_malloc(KB);
    if (ptr == NULL) {
        printf("Error: allocation failed\n");
        goto exit;
    }

    expected_nodemask = numa_allocate_nodemask();
    status = memkind_hbw_all_get_mbind_nodemask(NULL, expected_nodemask->maskp,
                                                expected_nodemask->size);
    if (status != MEMKIND_ERROR_ENVIRON) {
        printf("Error: wrong return value from memkind_hbw_all_get_mbind_nodemask()\n");
        printf("Expected: %d\n", MEMKIND_ERROR_ENVIRON);
        printf("Actual: %d\n", status);
        goto exit;
    }

    returned_nodemask = numa_allocate_nodemask();
    status = get_mempolicy(NULL, returned_nodemask->maskp, returned_nodemask->size,
                           ptr, MPOL_F_ADDR);
    if (status) {
        printf("Error: get_mempolicy() returned %d\n", status);
        goto exit;
    }

    ret = numa_bitmask_equal(returned_nodemask, expected_nodemask);
    if (!ret) {
        printf("Error: Memkind hbw and allocated pointer nodemasks are not equal\n");
    }

exit:
    if (expected_nodemask) {
        numa_free_nodemask(expected_nodemask);
    }
    if (returned_nodemask) {
        numa_free_nodemask(returned_nodemask);
    }
    if (ptr) {
        hbw_free(ptr);
    }

    return ret;
}