-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #741 from kswiecicki/opt-pool-tracking-2
[umf] Make pool tracking optional
- Loading branch information
Showing
13 changed files
with
278 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
source/common/unified_malloc_framework/src/memory_pool_default.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* | ||
* Copyright (C) 2023 Intel Corporation | ||
* | ||
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
* See LICENSE.TXT | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
* | ||
*/ | ||
|
||
#include "memory_pool_internal.h" | ||
|
||
#include <umf/memory_pool.h> | ||
|
||
#include <assert.h> | ||
#include <stdlib.h> | ||
|
||
enum umf_result_t umfPoolCreate(const struct umf_memory_pool_ops_t *ops, | ||
umf_memory_provider_handle_t *providers, | ||
size_t numProviders, void *params, | ||
umf_memory_pool_handle_t *hPool) { | ||
if (!numProviders || !providers) { | ||
return UMF_RESULT_ERROR_INVALID_ARGUMENT; | ||
} | ||
|
||
enum umf_result_t ret = UMF_RESULT_SUCCESS; | ||
umf_memory_pool_handle_t pool = malloc(sizeof(struct umf_memory_pool_t)); | ||
if (!pool) { | ||
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY; | ||
} | ||
|
||
assert(ops->version == UMF_VERSION_CURRENT); | ||
|
||
pool->providers = | ||
calloc(numProviders, sizeof(umf_memory_provider_handle_t)); | ||
if (!pool->providers) { | ||
ret = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY; | ||
goto err_providers_alloc; | ||
} | ||
|
||
size_t providerInd = 0; | ||
pool->numProviders = numProviders; | ||
|
||
for (providerInd = 0; providerInd < numProviders; providerInd++) { | ||
pool->providers[providerInd] = providers[providerInd]; | ||
} | ||
|
||
pool->ops = *ops; | ||
ret = ops->initialize(pool->providers, pool->numProviders, params, | ||
&pool->pool_priv); | ||
if (ret != UMF_RESULT_SUCCESS) { | ||
goto err_pool_init; | ||
} | ||
|
||
*hPool = pool; | ||
return UMF_RESULT_SUCCESS; | ||
|
||
err_pool_init: | ||
err_providers_alloc: | ||
free(pool); | ||
|
||
return ret; | ||
} | ||
|
||
void umfPoolDestroy(umf_memory_pool_handle_t hPool) { | ||
hPool->ops.finalize(hPool->pool_priv); | ||
free(hPool); | ||
} | ||
|
||
enum umf_result_t umfFree(void *ptr) { return UMF_RESULT_ERROR_NOT_SUPPORTED; } | ||
|
||
umf_memory_pool_handle_t umfPoolByPtr(const void *ptr) { return NULL; } | ||
|
||
enum umf_result_t | ||
umfPoolGetMemoryProviders(umf_memory_pool_handle_t hPool, size_t numProviders, | ||
umf_memory_provider_handle_t *hProviders, | ||
size_t *numProvidersRet) { | ||
if (hProviders && numProviders < hPool->numProviders) { | ||
return UMF_RESULT_ERROR_INVALID_ARGUMENT; | ||
} | ||
|
||
if (numProvidersRet) { | ||
*numProvidersRet = hPool->numProviders; | ||
} | ||
|
||
if (hProviders) { | ||
for (size_t i = 0; i < hPool->numProviders; i++) { | ||
hProviders[i] = hPool->providers[i]; | ||
} | ||
} | ||
|
||
return UMF_RESULT_SUCCESS; | ||
} |
37 changes: 37 additions & 0 deletions
37
source/common/unified_malloc_framework/src/memory_pool_internal.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* | ||
* Copyright (C) 2023 Intel Corporation | ||
* | ||
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
* See LICENSE.TXT | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
* | ||
*/ | ||
|
||
#ifndef UMF_MEMORY_POOL_INTERNAL_H | ||
#define UMF_MEMORY_POOL_INTERNAL_H 1 | ||
|
||
#include <umf/base.h> | ||
#include <umf/memory_pool_ops.h> | ||
#include <umf/memory_provider.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
struct umf_memory_pool_t { | ||
void *pool_priv; | ||
struct umf_memory_pool_ops_t ops; | ||
|
||
// Holds array of memory providers. All providers are wrapped | ||
// by memory tracking providers (owned and released by UMF). | ||
umf_memory_provider_handle_t *providers; | ||
|
||
size_t numProviders; | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* UMF_MEMORY_POOL_INTERNAL_H */ |
Oops, something went wrong.