|
Packit Service |
7f3b24 |
// SPDX-License-Identifier: BSD-2-Clause
|
|
Packit Service |
7f3b24 |
/* Copyright (C) 2014 - 2020 Intel Corporation. */
|
|
Packit |
345191 |
|
|
Packit |
345191 |
#include <memkind.h>
|
|
Packit |
345191 |
|
|
Packit |
345191 |
#include <stdlib.h>
|
|
Packit |
345191 |
#include <stdio.h>
|
|
Packit |
345191 |
#include <errno.h>
|
|
Packit |
345191 |
|
|
Packit |
345191 |
int main(int argc, char **argv)
|
|
Packit |
345191 |
{
|
|
Packit |
345191 |
const size_t size = 512;
|
|
Packit |
345191 |
char *default_str = NULL;
|
|
Packit |
345191 |
char *hugetlb_str = NULL;
|
|
Packit |
345191 |
char *hbw_str = NULL;
|
|
Packit |
345191 |
char *hbw_hugetlb_str = NULL;
|
|
Packit |
345191 |
char *hbw_preferred_str = NULL;
|
|
Packit |
345191 |
char *hbw_preferred_hugetlb_str = NULL;
|
|
Packit |
345191 |
char *hbw_interleave_str = NULL;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
default_str = (char *)memkind_malloc(MEMKIND_DEFAULT, size);
|
|
Packit |
345191 |
if (default_str == NULL) {
|
|
Packit |
345191 |
perror("memkind_malloc()");
|
|
Packit |
345191 |
fprintf(stderr, "Unable to allocate default string\n");
|
|
Packit |
345191 |
return errno ? -errno : 1;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
hugetlb_str = (char *)memkind_malloc(MEMKIND_HUGETLB, size);
|
|
Packit |
345191 |
if (hugetlb_str == NULL) {
|
|
Packit |
345191 |
perror("memkind_malloc()");
|
|
Packit |
345191 |
fprintf(stderr, "Unable to allocate hugetlb string\n");
|
|
Packit |
345191 |
return errno ? -errno : 1;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
hbw_str = (char *)memkind_malloc(MEMKIND_HBW, size);
|
|
Packit |
345191 |
if (hbw_str == NULL) {
|
|
Packit |
345191 |
perror("memkind_malloc()");
|
|
Packit |
345191 |
fprintf(stderr, "Unable to allocate hbw string\n");
|
|
Packit |
345191 |
return errno ? -errno : 1;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
hbw_hugetlb_str = (char *)memkind_malloc(MEMKIND_HBW_HUGETLB, size);
|
|
Packit |
345191 |
if (hbw_hugetlb_str == NULL) {
|
|
Packit |
345191 |
perror("memkind_malloc()");
|
|
Packit |
345191 |
fprintf(stderr, "Unable to allocate hbw_hugetlb string\n");
|
|
Packit |
345191 |
return errno ? -errno : 1;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
hbw_preferred_str = (char *)memkind_malloc(MEMKIND_HBW_PREFERRED, size);
|
|
Packit |
345191 |
if (hbw_preferred_str == NULL) {
|
|
Packit |
345191 |
perror("memkind_malloc()");
|
|
Packit |
345191 |
fprintf(stderr, "Unable to allocate hbw_preferred string\n");
|
|
Packit |
345191 |
return errno ? -errno : 1;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
hbw_preferred_hugetlb_str = (char *)memkind_malloc(
|
|
Packit |
345191 |
MEMKIND_HBW_PREFERRED_HUGETLB, size);
|
|
Packit |
345191 |
if (hbw_preferred_hugetlb_str == NULL) {
|
|
Packit |
345191 |
perror("memkind_malloc()");
|
|
Packit |
345191 |
fprintf(stderr, "Unable to allocate hbw_preferred_hugetlb string\n");
|
|
Packit |
345191 |
return errno ? -errno : 1;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
hbw_interleave_str = (char *)memkind_malloc(MEMKIND_HBW_INTERLEAVE, size);
|
|
Packit |
345191 |
if (hbw_interleave_str == NULL) {
|
|
Packit |
345191 |
perror("memkind_malloc()");
|
|
Packit |
345191 |
fprintf(stderr,"Unable to allocate hbw_interleave string\n");
|
|
Packit |
345191 |
return errno ? -errno : 1;
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
sprintf(default_str, "Hello world from standard memory\n");
|
|
Packit |
345191 |
sprintf(hugetlb_str, "Hello world from standard memory with 2 MB pages\n");
|
|
Packit |
345191 |
sprintf(hbw_str, "Hello world from high bandwidth memory\n");
|
|
Packit |
345191 |
sprintf(hbw_hugetlb_str, "Hello world from high bandwidth 2 MB paged memory\n");
|
|
Packit |
345191 |
sprintf(hbw_preferred_str,
|
|
Packit |
345191 |
"Hello world from high bandwidth memory if sufficient resources exist\n");
|
|
Packit |
345191 |
sprintf(hbw_preferred_hugetlb_str,
|
|
Packit |
345191 |
"Hello world from high bandwidth 2 MB paged memory if sufficient resources exist\n");
|
|
Packit |
345191 |
|
|
Packit |
345191 |
sprintf(hbw_interleave_str,
|
|
Packit |
345191 |
"Hello world from high bandwidth interleaved memory\n");
|
|
Packit |
345191 |
|
|
Packit |
345191 |
fprintf(stdout, "%s", default_str);
|
|
Packit |
345191 |
fprintf(stdout, "%s", hugetlb_str);
|
|
Packit |
345191 |
fprintf(stdout, "%s", hbw_str);
|
|
Packit |
345191 |
fprintf(stdout, "%s", hbw_hugetlb_str);
|
|
Packit |
345191 |
fprintf(stdout, "%s", hbw_preferred_str);
|
|
Packit |
345191 |
fprintf(stdout, "%s", hbw_preferred_hugetlb_str);
|
|
Packit |
345191 |
fprintf(stdout, "%s", hbw_interleave_str);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
memkind_free(MEMKIND_HBW_INTERLEAVE, hbw_interleave_str);
|
|
Packit |
345191 |
memkind_free(MEMKIND_HBW_PREFERRED_HUGETLB, hbw_preferred_hugetlb_str);
|
|
Packit |
345191 |
memkind_free(MEMKIND_HBW_PREFERRED, hbw_preferred_str);
|
|
Packit |
345191 |
memkind_free(MEMKIND_HBW_HUGETLB, hbw_hugetlb_str);
|
|
Packit |
345191 |
memkind_free(MEMKIND_HBW, hbw_str);
|
|
Packit |
345191 |
memkind_free(MEMKIND_HUGETLB, hugetlb_str);
|
|
Packit |
345191 |
memkind_free(MEMKIND_DEFAULT, default_str);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
return 0;
|
|
Packit |
345191 |
}
|