diff --git a/benchmark/benchmark_umf.hpp b/benchmark/benchmark_umf.hpp index 0bc93a49a7..cd4b31ae45 100644 --- a/benchmark/benchmark_umf.hpp +++ b/benchmark/benchmark_umf.hpp @@ -71,7 +71,7 @@ struct provider_interface { } } - virtual umf_memory_provider_ops_t * + virtual const umf_memory_provider_ops_t * getOps([[maybe_unused]] ::benchmark::State &state) = 0; virtual params_ptr getParams([[maybe_unused]] ::benchmark::State &state) { @@ -129,7 +129,7 @@ struct pool_interface { provider.TearDown(state); }; - virtual umf_memory_pool_ops_t * + virtual const umf_memory_pool_ops_t * getOps([[maybe_unused]] ::benchmark::State &state) = 0; virtual params_ptr getParams([[maybe_unused]] ::benchmark::State &state) { @@ -189,7 +189,7 @@ struct os_provider : public provider_interface { deleter}; } - umf_memory_provider_ops_t * + const umf_memory_provider_ops_t * getOps([[maybe_unused]] ::benchmark::State &state) override { return umfOsMemoryProviderOps(); } @@ -245,7 +245,7 @@ struct fixed_provider : public provider_interface { deleter}; } - umf_memory_provider_ops_t * + const umf_memory_provider_ops_t * getOps([[maybe_unused]] ::benchmark::State &state) override { return umfFixedMemoryProviderOps(); } @@ -254,7 +254,7 @@ struct fixed_provider : public provider_interface { template struct proxy_pool : public pool_interface { - umf_memory_pool_ops_t * + const umf_memory_pool_ops_t * getOps([[maybe_unused]] ::benchmark::State &state) override { return umfProxyPoolOps(); } @@ -264,7 +264,7 @@ struct proxy_pool : public pool_interface { template struct disjoint_pool : public pool_interface { - umf_memory_pool_ops_t * + const umf_memory_pool_ops_t * getOps([[maybe_unused]] ::benchmark::State &state) override { return umfDisjointPoolOps(); } @@ -319,7 +319,7 @@ struct disjoint_pool : public pool_interface { #ifdef UMF_POOL_JEMALLOC_ENABLED template struct jemalloc_pool : public pool_interface { - umf_memory_pool_ops_t * + const umf_memory_pool_ops_t * getOps([[maybe_unused]] ::benchmark::State &state) override { return umfJemallocPoolOps(); } @@ -333,7 +333,7 @@ struct jemalloc_pool : public pool_interface { #ifdef UMF_POOL_SCALABLE_ENABLED template struct scalable_pool : public pool_interface { - umf_memory_pool_ops_t * + const umf_memory_pool_ops_t * getOps([[maybe_unused]] ::benchmark::State &state) override { return umfScalablePoolOps(); } diff --git a/benchmark/multithread.cpp b/benchmark/multithread.cpp index d00ffba907..fac2d063a3 100644 --- a/benchmark/multithread.cpp +++ b/benchmark/multithread.cpp @@ -27,8 +27,9 @@ struct bench_params { size_t alloc_size = 64; }; -using poolCreateExtParams = std::tuple; +using poolCreateExtParams = + std::tuple; static auto poolCreateExtUnique(poolCreateExtParams params) { umf_memory_pool_handle_t hPool; diff --git a/examples/basic/basic.c b/examples/basic/basic.c index cf76de3199..41e48c6f64 100644 --- a/examples/basic/basic.c +++ b/examples/basic/basic.c @@ -22,7 +22,7 @@ int main(void) { // Allocations are made with mmap. The default values of params result // in an mmap call like this: // mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0) - umf_memory_provider_ops_t *provider_ops = umfOsMemoryProviderOps(); + const umf_memory_provider_ops_t *provider_ops = umfOsMemoryProviderOps(); umf_os_memory_provider_params_handle_t params = NULL; umf_memory_provider_handle_t provider; @@ -69,7 +69,7 @@ int main(void) { printf("Freed memory at %p\n", ptr_provider); // Create a memory pool - umf_memory_pool_ops_t *pool_ops = umfScalablePoolOps(); + const umf_memory_pool_ops_t *pool_ops = umfScalablePoolOps(); void *pool_params = NULL; umf_pool_create_flags_t flags = 0; umf_memory_pool_handle_t pool; diff --git a/examples/custom_file_provider/custom_file_provider.c b/examples/custom_file_provider/custom_file_provider.c index cc08b532fd..6454bb78f0 100644 --- a/examples/custom_file_provider/custom_file_provider.c +++ b/examples/custom_file_provider/custom_file_provider.c @@ -40,7 +40,7 @@ typedef struct file_params_t { } file_params_t; // Function to initialize the file provider -static umf_result_t file_init(void *params, void **provider) { +static umf_result_t file_init(const void *params, void **provider) { file_provider_t *file_provider = NULL; if (params == NULL || provider == NULL) { @@ -48,7 +48,7 @@ static umf_result_t file_init(void *params, void **provider) { return UMF_RESULT_ERROR_INVALID_ARGUMENT; } - file_params_t *file_params = (file_params_t *)params; + const file_params_t *file_params = params; int page_size = 0; umf_result_t ret = UMF_RESULT_SUCCESS; @@ -224,7 +224,7 @@ static umf_result_t file_get_recommended_page_size(void *provider, size_t size, } // Function to get the minimum page size of the file provider -static umf_result_t file_get_min_page_size(void *provider, void *ptr, +static umf_result_t file_get_min_page_size(void *provider, const void *ptr, size_t *pageSize) { (void)ptr; // Unused parameter file_provider_t *file_provider = (file_provider_t *)provider; @@ -291,7 +291,7 @@ int main(void) { printf("Freed memory at %p\n", ptr_provider); // Create a memory pool - umf_memory_pool_ops_t *pool_ops = umfScalablePoolOps(); + const umf_memory_pool_ops_t *pool_ops = umfScalablePoolOps(); void *pool_params = NULL; umf_pool_create_flags_t flags = 0; umf_memory_pool_handle_t pool; diff --git a/include/umf/memory_pool.h b/include/umf/memory_pool.h index ed3d1eb0dc..c46cac7d6b 100644 --- a/include/umf/memory_pool.h +++ b/include/umf/memory_pool.h @@ -51,8 +51,8 @@ typedef uint32_t umf_pool_create_flags_t; /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure. /// umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops, - umf_memory_provider_handle_t provider, void *params, - umf_pool_create_flags_t flags, + umf_memory_provider_handle_t provider, + const void *params, umf_pool_create_flags_t flags, umf_memory_pool_handle_t *hPool); /// @@ -106,7 +106,7 @@ void *umfPoolRealloc(umf_memory_pool_handle_t hPool, void *ptr, size_t size); /// @param ptr pointer to the allocated memory /// @return size of the memory block allocated from the \p hPool /// -size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool, void *ptr); +size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool, const void *ptr); /// /// @brief Frees the memory space of the specified \p hPool pointed by \p ptr diff --git a/include/umf/memory_pool_ops.h b/include/umf/memory_pool_ops.h index bf44383b44..1c97722687 100644 --- a/include/umf/memory_pool_ops.h +++ b/include/umf/memory_pool_ops.h @@ -20,7 +20,7 @@ extern "C" { /// @brief Version of the Memory Pool ops structure. /// NOTE: This is equal to the latest UMF version, in which the ops structure /// has been modified. -#define UMF_POOL_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 11) +#define UMF_POOL_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 12) /// /// @brief This structure comprises function pointers used by corresponding umfPool* @@ -42,7 +42,7 @@ typedef struct umf_memory_pool_ops_t { /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure. /// umf_result_t (*initialize)(umf_memory_provider_handle_t provider, - void *params, void **pool); + const void *params, void **pool); /// /// @brief Finalizes memory pool @@ -94,7 +94,7 @@ typedef struct umf_memory_pool_ops_t { /// @param ptr pointer to the allocated memory /// @return size of the memory block allocated from the \p pool /// - size_t (*malloc_usable_size)(void *pool, void *ptr); + size_t (*malloc_usable_size)(void *pool, const void *ptr); /// /// @brief Frees the memory space of the specified \p pool pointed by \p ptr diff --git a/include/umf/memory_provider.h b/include/umf/memory_provider.h index cff6f9eecb..fb843274af 100644 --- a/include/umf/memory_provider.h +++ b/include/umf/memory_provider.h @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2023-2024 Intel Corporation + * Copyright (C) 2023-2025 Intel Corporation * * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception @@ -45,7 +45,7 @@ typedef struct umf_memory_provider_t *umf_memory_provider_handle_t; /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure. /// umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops, - void *params, + const void *params, umf_memory_provider_handle_t *hProvider); /// @@ -125,7 +125,7 @@ umfMemoryProviderGetRecommendedPageSize(umf_memory_provider_handle_t hProvider, /// umf_result_t umfMemoryProviderGetMinPageSize(umf_memory_provider_handle_t hProvider, - void *ptr, size_t *pageSize); + const void *ptr, size_t *pageSize); /// /// @brief Discard physical pages within the virtual memory mapping associated at the given addr diff --git a/include/umf/memory_provider_ops.h b/include/umf/memory_provider_ops.h index 638f2975ba..a531c10ba1 100644 --- a/include/umf/memory_provider_ops.h +++ b/include/umf/memory_provider_ops.h @@ -19,7 +19,7 @@ extern "C" { /// @brief Version of the Memory Provider ops structure. /// NOTE: This is equal to the latest UMF version, in which the ops structure /// has been modified. -#define UMF_PROVIDER_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 11) +#define UMF_PROVIDER_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 12) /// /// @brief This structure comprises optional function pointers used @@ -156,7 +156,7 @@ typedef struct umf_memory_provider_ops_t { /// @param provider returns pointer to the provider /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure. /// - umf_result_t (*initialize)(void *params, void **provider); + umf_result_t (*initialize)(const void *params, void **provider); /// /// @brief Finalizes memory provider. @@ -230,7 +230,7 @@ typedef struct umf_memory_provider_ops_t { /// @param pageSize [out] pointer to the minimum possible page size /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure. /// - umf_result_t (*get_min_page_size)(void *provider, void *ptr, + umf_result_t (*get_min_page_size)(void *provider, const void *ptr, size_t *pageSize); /// diff --git a/include/umf/pools/pool_disjoint.h b/include/umf/pools/pool_disjoint.h index a1558b85bf..640184c975 100644 --- a/include/umf/pools/pool_disjoint.h +++ b/include/umf/pools/pool_disjoint.h @@ -106,7 +106,7 @@ umf_result_t umfDisjointPoolParamsSetName(umf_disjoint_pool_params_handle_t hParams, const char *name); -umf_memory_pool_ops_t *umfDisjointPoolOps(void); +const umf_memory_pool_ops_t *umfDisjointPoolOps(void); #ifdef __cplusplus } diff --git a/include/umf/pools/pool_jemalloc.h b/include/umf/pools/pool_jemalloc.h index 6fae911c0c..8d5b090d6c 100644 --- a/include/umf/pools/pool_jemalloc.h +++ b/include/umf/pools/pool_jemalloc.h @@ -43,7 +43,7 @@ umf_result_t umfJemallocPoolParamsSetNumArenas(umf_jemalloc_pool_params_handle_t hParams, size_t numArenas); -umf_memory_pool_ops_t *umfJemallocPoolOps(void); +const umf_memory_pool_ops_t *umfJemallocPoolOps(void); #ifdef __cplusplus } diff --git a/include/umf/pools/pool_proxy.h b/include/umf/pools/pool_proxy.h index c13cb3b228..df405e8d98 100644 --- a/include/umf/pools/pool_proxy.h +++ b/include/umf/pools/pool_proxy.h @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024-2025 Intel Corporation * * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception @@ -18,7 +18,7 @@ extern "C" { #endif -umf_memory_pool_ops_t *umfProxyPoolOps(void); +const umf_memory_pool_ops_t *umfProxyPoolOps(void); #ifdef __cplusplus } diff --git a/include/umf/pools/pool_scalable.h b/include/umf/pools/pool_scalable.h index 1915ad0b7a..f93e8d38e9 100644 --- a/include/umf/pools/pool_scalable.h +++ b/include/umf/pools/pool_scalable.h @@ -55,7 +55,7 @@ umfScalablePoolParamsSetKeepAllMemory(umf_scalable_pool_params_handle_t hParams, /// @brief Return \p ops structure containing pointers to the scalable pool implementation. /// @return pointer to the \p umf_memory_pool_ops_t struct. -umf_memory_pool_ops_t *umfScalablePoolOps(void); +const umf_memory_pool_ops_t *umfScalablePoolOps(void); #ifdef __cplusplus } diff --git a/include/umf/providers/provider_cuda.h b/include/umf/providers/provider_cuda.h index 95f2634fbc..0c07e74826 100644 --- a/include/umf/providers/provider_cuda.h +++ b/include/umf/providers/provider_cuda.h @@ -61,7 +61,7 @@ umf_result_t umfCUDAMemoryProviderParamsSetMemoryType( umf_result_t umfCUDAMemoryProviderParamsSetAllocFlags( umf_cuda_memory_provider_params_handle_t hParams, unsigned int flags); -umf_memory_provider_ops_t *umfCUDAMemoryProviderOps(void); +const umf_memory_provider_ops_t *umfCUDAMemoryProviderOps(void); #ifdef __cplusplus } diff --git a/include/umf/providers/provider_devdax_memory.h b/include/umf/providers/provider_devdax_memory.h index 0fb5218bcf..91678ef7fd 100644 --- a/include/umf/providers/provider_devdax_memory.h +++ b/include/umf/providers/provider_devdax_memory.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024-2025 Intel Corporation * * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception @@ -65,7 +65,7 @@ typedef enum umf_devdax_memory_provider_native_error { UMF_DEVDAX_RESULT_ERROR_PURGE_FORCE_FAILED, ///< Force purging failed } umf_devdax_memory_provider_native_error_t; -umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void); +const umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void); #ifdef __cplusplus } diff --git a/include/umf/providers/provider_file_memory.h b/include/umf/providers/provider_file_memory.h index f652e2cb8a..fed5147cc6 100644 --- a/include/umf/providers/provider_file_memory.h +++ b/include/umf/providers/provider_file_memory.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024-2025 Intel Corporation * * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception @@ -66,7 +66,7 @@ typedef enum umf_file_memory_provider_native_error { UMF_FILE_RESULT_ERROR_PURGE_FORCE_FAILED, ///< Force purging failed } umf_file_memory_provider_native_error_t; -umf_memory_provider_ops_t *umfFileMemoryProviderOps(void); +const umf_memory_provider_ops_t *umfFileMemoryProviderOps(void); #ifdef __cplusplus } diff --git a/include/umf/providers/provider_fixed_memory.h b/include/umf/providers/provider_fixed_memory.h index 2351faf312..00273d5650 100644 --- a/include/umf/providers/provider_fixed_memory.h +++ b/include/umf/providers/provider_fixed_memory.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024-2025 Intel Corporation * * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception @@ -49,7 +49,7 @@ umf_result_t umfFixedMemoryProviderParamsDestroy( /// @brief Retrieve the operations structure for the Fixed Memory Provider. /// @return Pointer to the umf_memory_provider_ops_t structure. -umf_memory_provider_ops_t *umfFixedMemoryProviderOps(void); +const umf_memory_provider_ops_t *umfFixedMemoryProviderOps(void); /// @brief Fixed Memory Provider operation results typedef enum umf_fixed_memory_provider_native_error { diff --git a/include/umf/providers/provider_level_zero.h b/include/umf/providers/provider_level_zero.h index b20fb40d59..895922b4ce 100644 --- a/include/umf/providers/provider_level_zero.h +++ b/include/umf/providers/provider_level_zero.h @@ -91,7 +91,7 @@ umf_result_t umfLevelZeroMemoryProviderParamsSetDeviceOrdinal( umf_level_zero_memory_provider_params_handle_t hParams, uint32_t deviceOrdinal); -umf_memory_provider_ops_t *umfLevelZeroMemoryProviderOps(void); +const umf_memory_provider_ops_t *umfLevelZeroMemoryProviderOps(void); #ifdef __cplusplus } diff --git a/include/umf/providers/provider_os_memory.h b/include/umf/providers/provider_os_memory.h index 90455cad19..17bea65b02 100644 --- a/include/umf/providers/provider_os_memory.h +++ b/include/umf/providers/provider_os_memory.h @@ -146,7 +146,7 @@ typedef enum umf_os_memory_provider_native_error { UMF_OS_RESULT_ERROR_TOPO_DISCOVERY_FAILED, ///< HWLOC topology discovery failed } umf_os_memory_provider_native_error_t; -umf_memory_provider_ops_t *umfOsMemoryProviderOps(void); +const umf_memory_provider_ops_t *umfOsMemoryProviderOps(void); #ifdef __cplusplus } diff --git a/src/base_alloc/base_alloc_global.c b/src/base_alloc/base_alloc_global.c index ecec3367c9..23cf91b571 100644 --- a/src/base_alloc/base_alloc_global.c +++ b/src/base_alloc/base_alloc_global.c @@ -130,7 +130,7 @@ static void *add_metadata_and_align(void *ptr, size_t size, size_t alignment) { // return original ptr (the one that has been passed to add_metadata_and_align) // along with total allocation size (needed to find proper alloc class // in free) and usable size -static void *get_original_alloc(void *user_ptr, size_t *total_size, +static void *get_original_alloc(const void *user_ptr, size_t *total_size, size_t *usable_size) { assert(user_ptr); @@ -233,7 +233,7 @@ void umf_ba_global_free(void *ptr) { umf_ba_free(BASE_ALLOC.ac[ac_index], ptr); } -size_t umf_ba_global_malloc_usable_size(void *ptr) { +size_t umf_ba_global_malloc_usable_size(const void *ptr) { if (!ptr) { return 0; } diff --git a/src/base_alloc/base_alloc_global.h b/src/base_alloc/base_alloc_global.h index bd55d352ff..4cec997255 100644 --- a/src/base_alloc/base_alloc_global.h +++ b/src/base_alloc/base_alloc_global.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024-2025 Intel Corporation * * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception @@ -20,7 +20,7 @@ void *umf_ba_global_alloc(size_t size); void umf_ba_global_free(void *ptr); void umf_ba_destroy_global(void); bool umf_ba_global_is_destroyed(void); -size_t umf_ba_global_malloc_usable_size(void *ptr); +size_t umf_ba_global_malloc_usable_size(const void *ptr); void *umf_ba_global_aligned_alloc(size_t size, size_t alignment); #ifdef __cplusplus diff --git a/src/memory_pool.c b/src/memory_pool.c index c948823340..985600d2a4 100644 --- a/src/memory_pool.c +++ b/src/memory_pool.c @@ -50,7 +50,7 @@ static umf_result_t umfDefaultCtlPoolHandle(void *hPool, int operationType, static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops, umf_memory_provider_handle_t provider, - void *params, + const void *params, umf_pool_create_flags_t flags, umf_memory_pool_handle_t *hPool) { if (!ops || !provider || !hPool) { @@ -169,8 +169,8 @@ umf_result_t umfPoolGetMemoryProvider(umf_memory_pool_handle_t hPool, } umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops, - umf_memory_provider_handle_t provider, void *params, - umf_pool_create_flags_t flags, + umf_memory_provider_handle_t provider, + const void *params, umf_pool_create_flags_t flags, umf_memory_pool_handle_t *hPool) { libumfInit(); @@ -205,7 +205,8 @@ void *umfPoolRealloc(umf_memory_pool_handle_t hPool, void *ptr, size_t size) { return hPool->ops.realloc(hPool->pool_priv, ptr, size); } -size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool, void *ptr) { +size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool, + const void *ptr) { UMF_CHECK((hPool != NULL), 0); return hPool->ops.malloc_usable_size(hPool->pool_priv, ptr); } diff --git a/src/memory_provider.c b/src/memory_provider.c index fdc8725e09..627ad23ac2 100644 --- a/src/memory_provider.c +++ b/src/memory_provider.c @@ -184,7 +184,7 @@ static bool validateOps(const umf_memory_provider_ops_t *ops) { } umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops, - void *params, + const void *params, umf_memory_provider_handle_t *hProvider) { libumfInit(); if (!ops || !hProvider || !validateOps(ops)) { @@ -281,7 +281,7 @@ umfMemoryProviderGetRecommendedPageSize(umf_memory_provider_handle_t hProvider, umf_result_t umfMemoryProviderGetMinPageSize(umf_memory_provider_handle_t hProvider, - void *ptr, size_t *pageSize) { + const void *ptr, size_t *pageSize) { UMF_CHECK((hProvider != NULL), UMF_RESULT_ERROR_INVALID_ARGUMENT); UMF_CHECK((pageSize != NULL), UMF_RESULT_ERROR_INVALID_ARGUMENT); umf_result_t res = hProvider->ops.get_min_page_size( diff --git a/src/pool/pool_disjoint.c b/src/pool/pool_disjoint.c index 0bdd346b8c..8ce9f70dd9 100644 --- a/src/pool/pool_disjoint.c +++ b/src/pool/pool_disjoint.c @@ -571,14 +571,13 @@ static void *disjoint_pool_allocate(disjoint_pool_t *pool, size_t size) { } umf_result_t disjoint_pool_initialize(umf_memory_provider_handle_t provider, - void *params, void **ppPool) { + const void *params, void **ppPool) { // TODO set defaults when user pass the NULL as params if (!provider || !params || !ppPool) { return UMF_RESULT_ERROR_INVALID_ARGUMENT; } - umf_disjoint_pool_params_t *dp_params = - (umf_disjoint_pool_params_t *)params; + const umf_disjoint_pool_params_t *dp_params = params; // min_bucket_size parameter must be a power of 2 for bucket sizes // to generate correctly. @@ -793,7 +792,7 @@ void *disjoint_pool_aligned_malloc(void *pool, size_t size, size_t alignment) { return aligned_ptr; } -static size_t get_chunk_idx(void *ptr, slab_t *slab) { +static size_t get_chunk_idx(const void *ptr, slab_t *slab) { return (((uintptr_t)ptr - (uintptr_t)slab->mem_ptr) / slab->bucket->size); } @@ -801,7 +800,7 @@ static void *get_unaligned_ptr(size_t chunk_idx, slab_t *slab) { return (void *)((uintptr_t)slab->mem_ptr + chunk_idx * slab->bucket->size); } -size_t disjoint_pool_malloc_usable_size(void *pool, void *ptr) { +size_t disjoint_pool_malloc_usable_size(void *pool, const void *ptr) { disjoint_pool_t *disjoint_pool = (disjoint_pool_t *)pool; if (ptr == NULL) { return 0; @@ -942,7 +941,7 @@ static umf_memory_pool_ops_t UMF_DISJOINT_POOL_OPS = { .get_last_allocation_error = disjoint_pool_get_last_allocation_error, }; -umf_memory_pool_ops_t *umfDisjointPoolOps(void) { +const umf_memory_pool_ops_t *umfDisjointPoolOps(void) { return &UMF_DISJOINT_POOL_OPS; } diff --git a/src/pool/pool_jemalloc.c b/src/pool/pool_jemalloc.c index 80baf3a8f1..bed78ce26b 100644 --- a/src/pool/pool_jemalloc.c +++ b/src/pool/pool_jemalloc.c @@ -22,7 +22,7 @@ #ifndef UMF_POOL_JEMALLOC_ENABLED -umf_memory_pool_ops_t *umfJemallocPoolOps(void) { return NULL; } +const umf_memory_pool_ops_t *umfJemallocPoolOps(void) { return NULL; } umf_result_t umfJemallocPoolParamsCreate(umf_jemalloc_pool_params_handle_t *hParams) { (void)hParams; // unused @@ -424,15 +424,14 @@ static void *op_aligned_alloc(void *pool, size_t size, size_t alignment) { } static umf_result_t op_initialize(umf_memory_provider_handle_t provider, - void *params, void **out_pool) { + const void *params, void **out_pool) { assert(provider); assert(out_pool); extent_hooks_t *pHooks = &arena_extent_hooks; size_t unsigned_size = sizeof(unsigned); int err; - umf_jemalloc_pool_params_t *jemalloc_params = - (umf_jemalloc_pool_params_t *)params; + const umf_jemalloc_pool_params_t *jemalloc_params = params; size_t n_arenas = 0; if (jemalloc_params) { @@ -515,9 +514,11 @@ static void op_finalize(void *pool) { VALGRIND_DO_DESTROY_MEMPOOL(pool); } -static size_t op_malloc_usable_size(void *pool, void *ptr) { +static size_t op_malloc_usable_size(void *pool, const void *ptr) { (void)pool; // not used - return je_malloc_usable_size(ptr); + // Remove the 'const' qualifier because the je_malloc_usable_size + // function requires a non-const pointer. + return je_malloc_usable_size((void *)ptr); } static umf_result_t op_get_last_allocation_error(void *pool) { @@ -538,7 +539,7 @@ static umf_memory_pool_ops_t UMF_JEMALLOC_POOL_OPS = { .get_last_allocation_error = op_get_last_allocation_error, }; -umf_memory_pool_ops_t *umfJemallocPoolOps(void) { +const umf_memory_pool_ops_t *umfJemallocPoolOps(void) { return &UMF_JEMALLOC_POOL_OPS; } diff --git a/src/pool/pool_proxy.c b/src/pool/pool_proxy.c index eedddb0acb..91ae098cab 100644 --- a/src/pool/pool_proxy.c +++ b/src/pool/pool_proxy.c @@ -23,8 +23,8 @@ struct proxy_memory_pool { }; static umf_result_t -proxy_pool_initialize(umf_memory_provider_handle_t hProvider, void *params, - void **ppPool) { +proxy_pool_initialize(umf_memory_provider_handle_t hProvider, + const void *params, void **ppPool) { (void)params; // unused struct proxy_memory_pool *pool = @@ -107,7 +107,7 @@ static umf_result_t proxy_free(void *pool, void *ptr) { return umfMemoryProviderFree(hPool->hProvider, ptr, size); } -static size_t proxy_malloc_usable_size(void *pool, void *ptr) { +static size_t proxy_malloc_usable_size(void *pool, const void *ptr) { assert(pool); (void)pool; @@ -134,4 +134,6 @@ static umf_memory_pool_ops_t UMF_PROXY_POOL_OPS = { .free = proxy_free, .get_last_allocation_error = proxy_get_last_allocation_error}; -umf_memory_pool_ops_t *umfProxyPoolOps(void) { return &UMF_PROXY_POOL_OPS; } +const umf_memory_pool_ops_t *umfProxyPoolOps(void) { + return &UMF_PROXY_POOL_OPS; +} diff --git a/src/pool/pool_scalable.c b/src/pool/pool_scalable.c index f688875292..ea0260659d 100644 --- a/src/pool/pool_scalable.c +++ b/src/pool/pool_scalable.c @@ -266,7 +266,7 @@ umfScalablePoolParamsSetKeepAllMemory(umf_scalable_pool_params_handle_t hParams, } static umf_result_t tbb_pool_initialize(umf_memory_provider_handle_t provider, - void *params, void **pool) { + const void *params, void **pool) { tbb_mem_pool_policy_t policy = {.pAlloc = tbb_raw_alloc_wrapper, .pFree = tbb_raw_free_wrapper, .granularity = DEFAULT_GRANULARITY, @@ -276,8 +276,7 @@ static umf_result_t tbb_pool_initialize(umf_memory_provider_handle_t provider, .reserved = 0}; if (params) { - umf_scalable_pool_params_handle_t scalable_params = - (umf_scalable_pool_params_handle_t)params; + const umf_scalable_pool_params_t *scalable_params = params; policy.granularity = scalable_params->granularity; policy.keep_all_memory = scalable_params->keep_all_memory; } @@ -401,9 +400,10 @@ static umf_result_t tbb_free(void *pool, void *ptr) { return UMF_RESULT_ERROR_UNKNOWN; } -static size_t tbb_malloc_usable_size(void *pool, void *ptr) { +static size_t tbb_malloc_usable_size(void *pool, const void *ptr) { tbb_memory_pool_t *pool_data = (tbb_memory_pool_t *)pool; - return tbb_callbacks.pool_msize(pool_data->tbb_pool, ptr); + // Remove the 'const' qualifier because the TBB pool_msize function requires a non-const pointer. + return tbb_callbacks.pool_msize(pool_data->tbb_pool, (void *)ptr); } static umf_result_t tbb_get_last_allocation_error(void *pool) { @@ -456,6 +456,6 @@ static umf_memory_pool_ops_t UMF_SCALABLE_POOL_OPS = { .get_last_allocation_error = tbb_get_last_allocation_error, .ctl = pool_ctl}; -umf_memory_pool_ops_t *umfScalablePoolOps(void) { +const umf_memory_pool_ops_t *umfScalablePoolOps(void) { return &UMF_SCALABLE_POOL_OPS; } diff --git a/src/provider/provider_cuda.c b/src/provider/provider_cuda.c index dd12d91847..f3e0658a5f 100644 --- a/src/provider/provider_cuda.c +++ b/src/provider/provider_cuda.c @@ -74,7 +74,7 @@ umf_result_t umfCUDAMemoryProviderParamsSetAllocFlags( return UMF_RESULT_ERROR_NOT_SUPPORTED; } -umf_memory_provider_ops_t *umfCUDAMemoryProviderOps(void) { +const umf_memory_provider_ops_t *umfCUDAMemoryProviderOps(void) { // not supported LOG_ERR("CUDA provider is disabled (UMF_BUILD_CUDA_PROVIDER is OFF)!"); return NULL; @@ -353,14 +353,13 @@ umf_result_t umfCUDAMemoryProviderParamsSetAllocFlags( return UMF_RESULT_SUCCESS; } -static umf_result_t cu_memory_provider_initialize(void *params, +static umf_result_t cu_memory_provider_initialize(const void *params, void **provider) { if (params == NULL) { return UMF_RESULT_ERROR_INVALID_ARGUMENT; } - umf_cuda_memory_provider_params_handle_t cu_params = - (umf_cuda_memory_provider_params_handle_t)params; + const umf_cuda_memory_provider_params_t *cu_params = params; if (cu_params->memory_type == UMF_MEMORY_TYPE_UNKNOWN || cu_params->memory_type > UMF_MEMORY_TYPE_SHARED) { @@ -613,7 +612,7 @@ static void cu_memory_provider_get_last_native_error(void *provider, } static umf_result_t cu_memory_provider_get_min_page_size(void *provider, - void *ptr, + const void *ptr, size_t *pageSize) { (void)ptr; @@ -756,7 +755,7 @@ static umf_memory_provider_ops_t UMF_CUDA_MEMORY_PROVIDER_OPS = { .ipc.close_ipc_handle = cu_memory_provider_close_ipc_handle, }; -umf_memory_provider_ops_t *umfCUDAMemoryProviderOps(void) { +const umf_memory_provider_ops_t *umfCUDAMemoryProviderOps(void) { return &UMF_CUDA_MEMORY_PROVIDER_OPS; } diff --git a/src/provider/provider_devdax_memory.c b/src/provider/provider_devdax_memory.c index 8e81971905..50e60cdb7b 100644 --- a/src/provider/provider_devdax_memory.c +++ b/src/provider/provider_devdax_memory.c @@ -21,7 +21,7 @@ #if defined(_WIN32) || defined(UMF_NO_HWLOC) -umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void) { +const umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void) { // not supported LOG_ERR("DevDax memory provider is disabled!"); return NULL; @@ -128,7 +128,7 @@ static void devdax_store_last_native_error(int32_t native_error, } static umf_result_t -devdax_translate_params(umf_devdax_memory_provider_params_t *in_params, +devdax_translate_params(const umf_devdax_memory_provider_params_t *in_params, devdax_memory_provider_t *provider) { umf_result_t result; @@ -148,15 +148,14 @@ static umf_result_t devdax_allocation_split_cb(void *provider, void *ptr, static umf_result_t devdax_allocation_merge_cb(void *provider, void *lowPtr, void *highPtr, size_t totalSize); -static umf_result_t devdax_initialize(void *params, void **provider) { +static umf_result_t devdax_initialize(const void *params, void **provider) { umf_result_t ret; if (params == NULL) { return UMF_RESULT_ERROR_INVALID_ARGUMENT; } - umf_devdax_memory_provider_params_t *in_params = - (umf_devdax_memory_provider_params_t *)params; + const umf_devdax_memory_provider_params_t *in_params = params; if (in_params->path == NULL) { LOG_ERR("devdax path is missing"); @@ -327,7 +326,7 @@ static umf_result_t devdax_get_recommended_page_size(void *provider, return UMF_RESULT_SUCCESS; } -static umf_result_t devdax_get_min_page_size(void *provider, void *ptr, +static umf_result_t devdax_get_min_page_size(void *provider, const void *ptr, size_t *page_size) { (void)ptr; // unused @@ -549,7 +548,7 @@ static umf_memory_provider_ops_t UMF_DEVDAX_MEMORY_PROVIDER_OPS = { .ipc.open_ipc_handle = devdax_open_ipc_handle, .ipc.close_ipc_handle = devdax_close_ipc_handle}; -umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void) { +const umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void) { return &UMF_DEVDAX_MEMORY_PROVIDER_OPS; } diff --git a/src/provider/provider_file_memory.c b/src/provider/provider_file_memory.c index 5cc377f320..74255fcc30 100644 --- a/src/provider/provider_file_memory.c +++ b/src/provider/provider_file_memory.c @@ -22,7 +22,7 @@ #if defined(_WIN32) || defined(UMF_NO_HWLOC) -umf_memory_provider_ops_t *umfFileMemoryProviderOps(void) { +const umf_memory_provider_ops_t *umfFileMemoryProviderOps(void) { // not supported LOG_ERR("File memory provider is disabled!"); return NULL; @@ -153,7 +153,7 @@ static void file_store_last_native_error(int32_t native_error, } static umf_result_t -file_translate_params(umf_file_memory_provider_params_t *in_params, +file_translate_params(const umf_file_memory_provider_params_t *in_params, file_memory_provider_t *provider) { umf_result_t result; @@ -185,15 +185,14 @@ static umf_result_t file_allocation_split_cb(void *provider, void *ptr, static umf_result_t file_allocation_merge_cb(void *provider, void *lowPtr, void *highPtr, size_t totalSize); -static umf_result_t file_initialize(void *params, void **provider) { +static umf_result_t file_initialize(const void *params, void **provider) { umf_result_t ret; if (params == NULL) { return UMF_RESULT_ERROR_INVALID_ARGUMENT; } - umf_file_memory_provider_params_t *in_params = - (umf_file_memory_provider_params_t *)params; + const umf_file_memory_provider_params_t *in_params = params; if (in_params->path == NULL) { LOG_ERR("file path is missing"); @@ -591,7 +590,7 @@ static umf_result_t file_get_recommended_page_size(void *provider, size_t size, return UMF_RESULT_SUCCESS; } -static umf_result_t file_get_min_page_size(void *provider, void *ptr, +static umf_result_t file_get_min_page_size(void *provider, const void *ptr, size_t *page_size) { (void)ptr; // unused @@ -871,7 +870,7 @@ static umf_memory_provider_ops_t UMF_FILE_MEMORY_PROVIDER_OPS = { .ipc.open_ipc_handle = file_open_ipc_handle, .ipc.close_ipc_handle = file_close_ipc_handle}; -umf_memory_provider_ops_t *umfFileMemoryProviderOps(void) { +const umf_memory_provider_ops_t *umfFileMemoryProviderOps(void) { return &UMF_FILE_MEMORY_PROVIDER_OPS; } diff --git a/src/provider/provider_fixed_memory.c b/src/provider/provider_fixed_memory.c index 034f6e3005..1ce9373139 100644 --- a/src/provider/provider_fixed_memory.c +++ b/src/provider/provider_fixed_memory.c @@ -94,15 +94,14 @@ static umf_result_t fixed_allocation_merge_cb(void *provider, void *lowPtr, return UMF_RESULT_SUCCESS; } -static umf_result_t fixed_initialize(void *params, void **provider) { +static umf_result_t fixed_initialize(const void *params, void **provider) { umf_result_t ret; if (params == NULL) { return UMF_RESULT_ERROR_INVALID_ARGUMENT; } - umf_fixed_memory_provider_params_t *in_params = - (umf_fixed_memory_provider_params_t *)params; + const umf_fixed_memory_provider_params_t *in_params = params; fixed_memory_provider_t *fixed_provider = umf_ba_global_alloc(sizeof(*fixed_provider)); @@ -221,7 +220,7 @@ static umf_result_t fixed_get_recommended_page_size(void *provider, size_t size, return UMF_RESULT_SUCCESS; } -static umf_result_t fixed_get_min_page_size(void *provider, void *ptr, +static umf_result_t fixed_get_min_page_size(void *provider, const void *ptr, size_t *page_size) { (void)ptr; // unused @@ -309,7 +308,7 @@ static umf_memory_provider_ops_t UMF_FIXED_MEMORY_PROVIDER_OPS = { .ipc.close_ipc_handle = NULL, .ctl = fixed_ctl}; -umf_memory_provider_ops_t *umfFixedMemoryProviderOps(void) { +const umf_memory_provider_ops_t *umfFixedMemoryProviderOps(void) { return &UMF_FIXED_MEMORY_PROVIDER_OPS; } diff --git a/src/provider/provider_level_zero.c b/src/provider/provider_level_zero.c index a4c68b391e..99228ec965 100644 --- a/src/provider/provider_level_zero.c +++ b/src/provider/provider_level_zero.c @@ -102,7 +102,7 @@ umf_result_t umfLevelZeroMemoryProviderParamsSetDeviceOrdinal( return UMF_RESULT_ERROR_NOT_SUPPORTED; } -umf_memory_provider_ops_t *umfLevelZeroMemoryProviderOps(void) { +const umf_memory_provider_ops_t *umfLevelZeroMemoryProviderOps(void) { // not supported LOG_ERR("L0 memory provider is disabled! (UMF_BUILD_LEVEL_ZERO_PROVIDER is " "OFF)"); @@ -542,14 +542,13 @@ static void ze_memory_provider_finalize(void *provider) { umf_ba_global_free(provider); } -static umf_result_t ze_memory_provider_initialize(void *params, +static umf_result_t ze_memory_provider_initialize(const void *params, void **provider) { if (params == NULL) { return UMF_RESULT_ERROR_INVALID_ARGUMENT; } - umf_level_zero_memory_provider_params_handle_t ze_params = - (umf_level_zero_memory_provider_params_handle_t)params; + const umf_level_zero_memory_provider_params_t *ze_params = params; if (!ze_params->level_zero_context_handle) { LOG_ERR("Level Zero context handle is NULL"); @@ -652,7 +651,7 @@ static void ze_memory_provider_get_last_native_error(void *provider, } static umf_result_t ze_memory_provider_get_min_page_size(void *provider, - void *ptr, + const void *ptr, size_t *pageSize) { ze_memory_provider_t *ze_provider = (ze_memory_provider_t *)provider; @@ -864,7 +863,7 @@ static umf_memory_provider_ops_t UMF_LEVEL_ZERO_MEMORY_PROVIDER_OPS = { .ipc.close_ipc_handle = ze_memory_provider_close_ipc_handle, }; -umf_memory_provider_ops_t *umfLevelZeroMemoryProviderOps(void) { +const umf_memory_provider_ops_t *umfLevelZeroMemoryProviderOps(void) { return &UMF_LEVEL_ZERO_MEMORY_PROVIDER_OPS; } diff --git a/src/provider/provider_os_memory.c b/src/provider/provider_os_memory.c index 638ef7ff5e..744293691c 100644 --- a/src/provider/provider_os_memory.c +++ b/src/provider/provider_os_memory.c @@ -24,7 +24,7 @@ // OS Memory Provider requires HWLOC #if defined(UMF_NO_HWLOC) -umf_memory_provider_ops_t *umfOsMemoryProviderOps(void) { return NULL; } +const umf_memory_provider_ops_t *umfOsMemoryProviderOps(void) { return NULL; } umf_result_t umfOsMemoryProviderParamsCreate( umf_os_memory_provider_params_handle_t *hParams) { @@ -321,7 +321,8 @@ static hwloc_membind_policy_t translate_numa_mode(umf_numa_mode_t mode, //return 1 if umf will bind memory directly to single NUMA node, based on internal algorithm //return 0 if umf will just set numa memory policy, and kernel will decide where to allocate memory -static int dedicated_node_bind(umf_os_memory_provider_params_t *in_params) { +static int +dedicated_node_bind(const umf_os_memory_provider_params_t *in_params) { if (in_params->numa_mode == UMF_NUMA_MODE_INTERLEAVE) { return in_params->part_size > 0; } @@ -371,7 +372,7 @@ static int validate_and_copy_shm_name(const char *in_shm_name, } static umf_result_t -create_fd_for_mmap(umf_os_memory_provider_params_t *in_params, +create_fd_for_mmap(const umf_os_memory_provider_params_t *in_params, os_memory_provider_t *provider) { umf_result_t result; @@ -442,7 +443,7 @@ create_fd_for_mmap(umf_os_memory_provider_params_t *in_params, } static umf_result_t -validatePartitions(umf_os_memory_provider_params_t *params) { +validatePartitions(const umf_os_memory_provider_params_t *params) { if (params->partitions_len == 0) { return UMF_RESULT_SUCCESS; @@ -469,11 +470,12 @@ validatePartitions(umf_os_memory_provider_params_t *params) { return UMF_RESULT_SUCCESS; } -static umf_result_t os_get_min_page_size(void *provider, void *ptr, +static umf_result_t os_get_min_page_size(void *provider, const void *ptr, size_t *page_size); -static umf_result_t validatePartSize(os_memory_provider_t *provider, - umf_os_memory_provider_params_t *params) { +static umf_result_t +validatePartSize(os_memory_provider_t *provider, + const umf_os_memory_provider_params_t *params) { size_t page_size; os_get_min_page_size(provider, NULL, &page_size); if (ALIGN_UP(params->part_size, page_size) < params->part_size) { @@ -494,7 +496,7 @@ static void free_bitmaps(os_memory_provider_t *provider) { static umf_result_t initializePartitions(os_memory_provider_t *provider, - umf_os_memory_provider_params_t *in_params) { + const umf_os_memory_provider_params_t *in_params) { if (provider->mode != UMF_NUMA_MODE_SPLIT) { return UMF_RESULT_SUCCESS; } @@ -535,8 +537,9 @@ initializePartitions(os_memory_provider_t *provider, return UMF_RESULT_SUCCESS; } -static umf_result_t translate_params(umf_os_memory_provider_params_t *in_params, - os_memory_provider_t *provider) { +static umf_result_t +translate_params(const umf_os_memory_provider_params_t *in_params, + os_memory_provider_t *provider) { umf_result_t result; result = utils_translate_mem_protection_flags(in_params->protection, @@ -603,15 +606,14 @@ static umf_result_t translate_params(umf_os_memory_provider_params_t *in_params, return UMF_RESULT_SUCCESS; } -static umf_result_t os_initialize(void *params, void **provider) { +static umf_result_t os_initialize(const void *params, void **provider) { umf_result_t ret; if (params == NULL) { return UMF_RESULT_ERROR_INVALID_ARGUMENT; } - umf_os_memory_provider_params_t *in_params = - (umf_os_memory_provider_params_t *)params; + const umf_os_memory_provider_params_t *in_params = params; if (in_params->visibility == UMF_MEM_MAP_SHARED && in_params->numa_mode != UMF_NUMA_MODE_DEFAULT) { @@ -1193,7 +1195,7 @@ static umf_result_t os_get_recommended_page_size(void *provider, size_t size, return UMF_RESULT_SUCCESS; } -static umf_result_t os_get_min_page_size(void *provider, void *ptr, +static umf_result_t os_get_min_page_size(void *provider, const void *ptr, size_t *page_size) { (void)ptr; // unused @@ -1468,7 +1470,7 @@ static umf_memory_provider_ops_t UMF_OS_MEMORY_PROVIDER_OPS = { .ctl = os_ctl, }; -umf_memory_provider_ops_t *umfOsMemoryProviderOps(void) { +const umf_memory_provider_ops_t *umfOsMemoryProviderOps(void) { return &UMF_OS_MEMORY_PROVIDER_OPS; } diff --git a/src/provider/provider_tracking.c b/src/provider/provider_tracking.c index 1bef858543..39d14540d0 100644 --- a/src/provider/provider_tracking.c +++ b/src/provider/provider_tracking.c @@ -772,14 +772,14 @@ static umf_result_t trackingFree(void *hProvider, void *ptr, size_t size) { return ret; } -static umf_result_t trackingInitialize(void *params, void **ret) { +static umf_result_t trackingInitialize(const void *params, void **ret) { umf_tracking_memory_provider_t *provider = umf_ba_global_alloc(sizeof(umf_tracking_memory_provider_t)); if (!provider) { return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY; } - *provider = *((umf_tracking_memory_provider_t *)params); + *provider = *((const umf_tracking_memory_provider_t *)params); if (provider->hUpstream == NULL || provider->hTracker == NULL || provider->pool == NULL || provider->ipcCache == NULL) { return UMF_RESULT_ERROR_INVALID_ARGUMENT; @@ -857,7 +857,7 @@ static umf_result_t trackingGetRecommendedPageSize(void *provider, size_t size, pageSize); } -static umf_result_t trackingGetMinPageSize(void *provider, void *ptr, +static umf_result_t trackingGetMinPageSize(void *provider, const void *ptr, size_t *pageSize) { umf_tracking_memory_provider_t *p = (umf_tracking_memory_provider_t *)provider; diff --git a/test/common/ipc_common.c b/test/common/ipc_common.c index bf116a6779..5e9b911be8 100644 --- a/test/common/ipc_common.c +++ b/test/common/ipc_common.c @@ -111,9 +111,11 @@ int consumer_connect(int port) { return ret; } -int run_consumer(int port, umf_memory_pool_ops_t *pool_ops, void *pool_params, - umf_memory_provider_ops_t *provider_ops, void *provider_params, - memcopy_callback_t memcopy_callback, void *memcopy_ctx) { +int run_consumer(int port, const umf_memory_pool_ops_t *pool_ops, + void *pool_params, + const umf_memory_provider_ops_t *provider_ops, + void *provider_params, memcopy_callback_t memcopy_callback, + void *memcopy_ctx) { char consumer_message[MSG_SIZE]; int producer_socket = -1; int ret = -1; @@ -327,9 +329,11 @@ int producer_connect(int port) { return -1; } -int run_producer(int port, umf_memory_pool_ops_t *pool_ops, void *pool_params, - umf_memory_provider_ops_t *provider_ops, void *provider_params, - memcopy_callback_t memcopy_callback, void *memcopy_ctx) { +int run_producer(int port, const umf_memory_pool_ops_t *pool_ops, + void *pool_params, + const umf_memory_provider_ops_t *provider_ops, + void *provider_params, memcopy_callback_t memcopy_callback, + void *memcopy_ctx) { int ret = -1; umf_memory_provider_handle_t provider = NULL; umf_result_t umf_result = UMF_RESULT_ERROR_UNKNOWN; diff --git a/test/common/ipc_common.h b/test/common/ipc_common.h index 89303899b6..c46c9a0643 100644 --- a/test/common/ipc_common.h +++ b/test/common/ipc_common.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Intel Corporation + * Copyright (C) 2024-2025 Intel Corporation * * Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception @@ -20,12 +20,16 @@ typedef void (*memcopy_callback_t)(void *dst, const void *src, size_t size, int producer_connect(int port); int consumer_connect(int port); -int run_producer(int port, umf_memory_pool_ops_t *pool_ops, void *pool_params, - umf_memory_provider_ops_t *provider_ops, void *provider_params, - memcopy_callback_t memcopy_callback, void *memcopy_ctx); +int run_producer(int port, const umf_memory_pool_ops_t *pool_ops, + void *pool_params, + const umf_memory_provider_ops_t *provider_ops, + void *provider_params, memcopy_callback_t memcopy_callback, + void *memcopy_ctx); -int run_consumer(int port, umf_memory_pool_ops_t *pool_ops, void *pool_params, - umf_memory_provider_ops_t *provider_ops, void *provider_params, - memcopy_callback_t memcopy_callback, void *memcopy_ctx); +int run_consumer(int port, const umf_memory_pool_ops_t *pool_ops, + void *pool_params, + const umf_memory_provider_ops_t *provider_ops, + void *provider_params, memcopy_callback_t memcopy_callback, + void *memcopy_ctx); #endif // UMF_TEST_IPC_COMMON_H diff --git a/test/common/pool.hpp b/test/common/pool.hpp index 558b9d665a..a8f10ace1a 100644 --- a/test/common/pool.hpp +++ b/test/common/pool.hpp @@ -28,8 +28,8 @@ namespace umf_test { umf_memory_pool_handle_t -createPoolChecked(umf_memory_pool_ops_t *ops, - umf_memory_provider_handle_t hProvider, void *params, +createPoolChecked(const umf_memory_pool_ops_t *ops, + umf_memory_provider_handle_t hProvider, const void *params, umf_pool_create_flags_t flags = 0) { umf_memory_pool_handle_t hPool; auto ret = umfPoolCreate(ops, hProvider, params, flags, &hPool); @@ -107,7 +107,7 @@ typedef struct pool_base_t { void *calloc(size_t, size_t) noexcept { return nullptr; } void *realloc(void *, size_t) noexcept { return nullptr; } void *aligned_malloc(size_t, size_t) noexcept { return nullptr; } - size_t malloc_usable_size(void *) noexcept { return 0; } + size_t malloc_usable_size(const void *) noexcept { return 0; } umf_result_t free(void *) noexcept { return UMF_RESULT_SUCCESS; } umf_result_t get_last_allocation_error() noexcept { return UMF_RESULT_SUCCESS; @@ -133,13 +133,13 @@ struct malloc_pool : public pool_base_t { return ::aligned_alloc(alignment, size); #endif } - size_t malloc_usable_size(void *ptr) noexcept { + size_t malloc_usable_size(const void *ptr) noexcept { #ifdef _WIN32 - return _msize(ptr); + return _msize((void *)ptr); #elif __APPLE__ - return ::malloc_size(ptr); + return ::malloc_size((void *)ptr); #else - return ::malloc_usable_size(ptr); + return ::malloc_usable_size((void *)ptr); #endif } umf_result_t free(void *ptr) noexcept { diff --git a/test/common/pool_null.c b/test/common/pool_null.c index 40d6626797..3f01d865b6 100644 --- a/test/common/pool_null.c +++ b/test/common/pool_null.c @@ -9,7 +9,7 @@ #include static umf_result_t nullInitialize(umf_memory_provider_handle_t provider, - void *params, void **pool) { + const void *params, void **pool) { (void)provider; (void)params; assert(provider); @@ -46,7 +46,7 @@ static void *nullAlignedMalloc(void *pool, size_t size, size_t alignment) { return NULL; } -static size_t nullMallocUsableSize(void *pool, void *ptr) { +static size_t nullMallocUsableSize(void *pool, const void *ptr) { (void)ptr; (void)pool; return 0; diff --git a/test/common/pool_trace.c b/test/common/pool_trace.c index 9a9e010193..63f33e1ef9 100644 --- a/test/common/pool_trace.c +++ b/test/common/pool_trace.c @@ -13,13 +13,13 @@ typedef struct trace_pool { } trace_pool_t; static umf_result_t traceInitialize(umf_memory_provider_handle_t provider, - void *params, void **pool) { + const void *params, void **pool) { trace_pool_t *trace_pool = (trace_pool_t *)malloc(sizeof(trace_pool_t)); if (NULL == trace_pool) { return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY; } - umf_pool_trace_params_t *pub_params = params; + const umf_pool_trace_params_t *pub_params = params; trace_pool->params.hUpstreamPool = pub_params->hUpstreamPool; trace_pool->params.trace_context = pub_params->trace_context; trace_pool->params.trace_handler = pub_params->trace_handler; @@ -66,7 +66,7 @@ static void *traceAlignedMalloc(void *pool, size_t size, size_t alignment) { alignment); } -static size_t traceMallocUsableSize(void *pool, void *ptr) { +static size_t traceMallocUsableSize(void *pool, const void *ptr) { trace_pool_t *trace_pool = (trace_pool_t *)pool; trace_pool->params.trace_handler(trace_pool->params.trace_context, diff --git a/test/common/provider.hpp b/test/common/provider.hpp index 38fe7336ec..d362d50063 100644 --- a/test/common/provider.hpp +++ b/test/common/provider.hpp @@ -48,7 +48,7 @@ typedef struct provider_base_t { [[maybe_unused]] size_t *pageSize) noexcept { return UMF_RESULT_ERROR_UNKNOWN; } - umf_result_t get_min_page_size([[maybe_unused]] void *ptr, + umf_result_t get_min_page_size([[maybe_unused]] const void *ptr, [[maybe_unused]] size_t *pageSize) noexcept { return UMF_RESULT_ERROR_UNKNOWN; } @@ -133,7 +133,7 @@ umf_memory_provider_ops_t BA_GLOBAL_PROVIDER_OPS = struct provider_mock_out_of_mem : public provider_base_t { provider_ba_global helper_prov; int allocNum = 0; - umf_result_t initialize(int *inAllocNum) noexcept { + umf_result_t initialize(const int *inAllocNum) noexcept { allocNum = *inAllocNum; return UMF_RESULT_SUCCESS; } @@ -152,7 +152,7 @@ struct provider_mock_out_of_mem : public provider_base_t { const char *get_name() noexcept { return "mock_out_of_mem"; } }; -umf_memory_provider_ops_t MOCK_OUT_OF_MEM_PROVIDER_OPS = +const umf_memory_provider_ops_t MOCK_OUT_OF_MEM_PROVIDER_OPS = umf_test::providerMakeCOps(); } // namespace umf_test diff --git a/test/common/provider_null.c b/test/common/provider_null.c index b4e54f9764..d74c3ffaa9 100644 --- a/test/common/provider_null.c +++ b/test/common/provider_null.c @@ -8,7 +8,7 @@ #include "provider_null.h" #include -static umf_result_t nullInitialize(void *params, void **pool) { +static umf_result_t nullInitialize(const void *params, void **pool) { (void)params; *pool = NULL; return UMF_RESULT_SUCCESS; @@ -47,8 +47,7 @@ static umf_result_t nullGetRecommendedPageSize(void *provider, size_t size, return UMF_RESULT_SUCCESS; } -static umf_result_t nullGetPageSize(void *provider, void *ptr, - +static umf_result_t nullGetPageSize(void *provider, const void *ptr, size_t *pageSize) { (void)provider; (void)ptr; diff --git a/test/common/provider_trace.c b/test/common/provider_trace.c index 20f44e8683..b30e922252 100644 --- a/test/common/provider_trace.c +++ b/test/common/provider_trace.c @@ -9,7 +9,7 @@ #include #include -static umf_result_t traceInitialize(void *params, void **pool) { +static umf_result_t traceInitialize(const void *params, void **pool) { umf_provider_trace_params_t *trace_pool = (umf_provider_trace_params_t *)malloc( sizeof(umf_provider_trace_params_t)); @@ -17,7 +17,7 @@ static umf_result_t traceInitialize(void *params, void **pool) { return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY; } - umf_provider_trace_params_t *pub_params = params; + const umf_provider_trace_params_t *pub_params = params; trace_pool->hUpstreamProvider = pub_params->hUpstreamProvider; trace_pool->own_upstream = pub_params->own_upstream; trace_pool->trace_context = pub_params->trace_context; @@ -77,8 +77,7 @@ static umf_result_t traceGetRecommendedPageSize(void *provider, size_t size, traceProvider->hUpstreamProvider, size, pageSize); } -static umf_result_t traceGetPageSize(void *provider, void *ptr, - +static umf_result_t traceGetPageSize(void *provider, const void *ptr, size_t *pageSize) { umf_provider_trace_params_t *traceProvider = (umf_provider_trace_params_t *)provider; diff --git a/test/ctl/ctl_api.cpp b/test/ctl/ctl_api.cpp index 93c059052e..09ecfa8777 100644 --- a/test/ctl/ctl_api.cpp +++ b/test/ctl/ctl_api.cpp @@ -23,7 +23,7 @@ using namespace umf_test; TEST_F(test, ctl_by_handle_os_provider) { umf_memory_provider_handle_t hProvider = NULL; umf_os_memory_provider_params_handle_t os_memory_provider_params = NULL; - umf_memory_provider_ops_t *os_provider_ops = umfOsMemoryProviderOps(); + const umf_memory_provider_ops_t *os_provider_ops = umfOsMemoryProviderOps(); if (os_provider_ops == NULL) { GTEST_SKIP() << "OS memory provider is not supported!"; } @@ -45,7 +45,7 @@ TEST_F(test, ctl_by_handle_os_provider) { // Create a memory provider and a memory pool umf_memory_provider_handle_t create_memory_provider() { - umf_memory_provider_ops_t *provider_ops = umfOsMemoryProviderOps(); + const umf_memory_provider_ops_t *provider_ops = umfOsMemoryProviderOps(); umf_os_memory_provider_params_handle_t params = NULL; umf_memory_provider_handle_t provider; @@ -81,7 +81,8 @@ class CtlTest : public ::testing::Test { pool = NULL; } - void instantiatePool(umf_memory_pool_ops_t *pool_ops, void *pool_params, + void instantiatePool(const umf_memory_pool_ops_t *pool_ops, + const void *pool_params, umf_pool_create_flags_t flags = 0) { freeResources(); provider = create_memory_provider(); diff --git a/test/ipcFixtures.hpp b/test/ipcFixtures.hpp index cf31ff7584..8b1f05e3e8 100644 --- a/test/ipcFixtures.hpp +++ b/test/ipcFixtures.hpp @@ -60,8 +60,8 @@ typedef umf_result_t (*pfnProviderParamsDestroy)(void *); // provider_ops, pfnProviderParamsCreate, pfnProviderParamsDestroy, // memoryAccessor using ipcTestParams = - std::tuple; @@ -166,11 +166,11 @@ struct umfIpcTest : umf_test::test, stats_type stat; MemoryAccessor *memAccessor = nullptr; - umf_memory_pool_ops_t *poolOps = nullptr; + const umf_memory_pool_ops_t *poolOps = nullptr; pfnPoolParamsCreate poolParamsCreate = nullptr; pfnPoolParamsDestroy poolParamsDestroy = nullptr; - umf_memory_provider_ops_t *providerOps = nullptr; + const umf_memory_provider_ops_t *providerOps = nullptr; pfnProviderParamsCreate providerParamsCreate = nullptr; pfnProviderParamsDestroy providerParamsDestroy = nullptr; size_t openedIpcCacheSize = 0; diff --git a/test/memoryPoolAPI.cpp b/test/memoryPoolAPI.cpp index e8071a2d81..f7f865a993 100644 --- a/test/memoryPoolAPI.cpp +++ b/test/memoryPoolAPI.cpp @@ -366,7 +366,7 @@ TEST_P(poolInitializeTest, errorPropagation) { struct pool : public umf_test::pool_base_t { umf_result_t initialize([[maybe_unused]] umf_memory_provider_handle_t provider, - umf_result_t *errorToReturn) noexcept { + const umf_result_t *errorToReturn) noexcept { return *errorToReturn; } }; diff --git a/test/memoryProviderAPI.cpp b/test/memoryProviderAPI.cpp index 720f11b413..6eb1b40e0b 100644 --- a/test/memoryProviderAPI.cpp +++ b/test/memoryProviderAPI.cpp @@ -330,7 +330,7 @@ INSTANTIATE_TEST_SUITE_P( TEST_P(providerInitializeTest, errorPropagation) { struct provider : public umf_test::provider_base_t { - umf_result_t initialize(umf_result_t *errorToReturn) noexcept { + umf_result_t initialize(const umf_result_t *errorToReturn) noexcept { return *errorToReturn; } }; diff --git a/test/poolFixtures.hpp b/test/poolFixtures.hpp index de5a54685a..f4c233ea34 100644 --- a/test/poolFixtures.hpp +++ b/test/poolFixtures.hpp @@ -28,8 +28,8 @@ typedef void *(*pfnProviderParamsCreate)(); typedef umf_result_t (*pfnProviderParamsDestroy)(void *); using poolCreateExtParams = - std::tuple; umf_test::pool_unique_handle_t poolCreateExtUnique(poolCreateExtParams params) { diff --git a/test/pools/disjoint_pool.cpp b/test/pools/disjoint_pool.cpp index 9bdef4f131..f64e619310 100644 --- a/test/pools/disjoint_pool.cpp +++ b/test/pools/disjoint_pool.cpp @@ -33,7 +33,7 @@ TEST_F(test, internals) { } umf_result_t - get_min_page_size([[maybe_unused]] void *ptr, + get_min_page_size([[maybe_unused]] const void *ptr, [[maybe_unused]] size_t *pageSize) noexcept { *pageSize = 1024; return UMF_RESULT_SUCCESS; @@ -56,7 +56,7 @@ TEST_F(test, internals) { // in "internals" test we use ops interface to directly manipulate the pool // structure - umf_memory_pool_ops_t *ops = umfDisjointPoolOps(); + const umf_memory_pool_ops_t *ops = umfDisjointPoolOps(); EXPECT_NE(ops, nullptr); disjoint_pool_t *pool; diff --git a/test/pools/pool_base_alloc.cpp b/test/pools/pool_base_alloc.cpp index 441ab37ec3..574803fd3f 100644 --- a/test/pools/pool_base_alloc.cpp +++ b/test/pools/pool_base_alloc.cpp @@ -31,7 +31,7 @@ struct base_alloc_pool : public umf_test::pool_base_t { UMF_RESULT_ERROR_NOT_SUPPORTED; return NULL; } - size_t malloc_usable_size(void *ptr) noexcept { + size_t malloc_usable_size(const void *ptr) noexcept { return umf_ba_global_malloc_usable_size(ptr); } umf_result_t free(void *ptr) noexcept { diff --git a/test/pools/scalable_pool.cpp b/test/pools/scalable_pool.cpp index 54c0128a40..540f4a1103 100644 --- a/test/pools/scalable_pool.cpp +++ b/test/pools/scalable_pool.cpp @@ -43,7 +43,7 @@ struct umfScalablePoolParamsTest struct provider_validator : public umf_test::provider_ba_global { using base_provider = umf_test::provider_ba_global; - umf_result_t initialize(validation_params_t *params) { + umf_result_t initialize(const validation_params_t *params) { EXPECT_NE(params, nullptr); expected_params = params; return UMF_RESULT_SUCCESS; @@ -57,7 +57,7 @@ struct umfScalablePoolParamsTest return base_provider::free(ptr, size); } - validation_params_t *expected_params; + const validation_params_t *expected_params; }; static constexpr umf_memory_provider_ops_t VALIDATOR_PROVIDER_OPS = diff --git a/test/provider_devdax_memory.cpp b/test/provider_devdax_memory.cpp index 6efeef90cb..7165961245 100644 --- a/test/provider_devdax_memory.cpp +++ b/test/provider_devdax_memory.cpp @@ -43,7 +43,8 @@ static int compare_native_error_str(const char *message, int error) { return strncmp(message, error_str, len); } -using providerCreateExtParams = std::tuple; +using providerCreateExtParams = + std::tuple; static void providerCreateExt(providerCreateExtParams params, umf_test::provider_unique_handle_t *handle) { diff --git a/test/provider_devdax_memory_not_impl.cpp b/test/provider_devdax_memory_not_impl.cpp index 3b97443a08..4687825d3f 100644 --- a/test/provider_devdax_memory_not_impl.cpp +++ b/test/provider_devdax_memory_not_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2024 Intel Corporation +// Copyright (C) 2024-2025 Intel Corporation // Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception @@ -25,6 +25,6 @@ TEST_F(test, devdax_provider_not_implemented) { umf_result = umfDevDaxMemoryProviderParamsSetProtection(nullptr, 0); EXPECT_EQ(umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED); - umf_memory_provider_ops_t *ops = umfDevDaxMemoryProviderOps(); + const umf_memory_provider_ops_t *ops = umfDevDaxMemoryProviderOps(); EXPECT_EQ(ops, nullptr); } diff --git a/test/provider_file_memory.cpp b/test/provider_file_memory.cpp index bcc9d26453..2445447315 100644 --- a/test/provider_file_memory.cpp +++ b/test/provider_file_memory.cpp @@ -39,7 +39,8 @@ static int compare_native_error_str(const char *message, int error) { return strncmp(message, error_str, len); } -using providerCreateExtParams = std::tuple; +using providerCreateExtParams = + std::tuple; static void providerCreateExt(providerCreateExtParams params, umf_test::provider_unique_handle_t *handle) { diff --git a/test/provider_file_memory_not_impl.cpp b/test/provider_file_memory_not_impl.cpp index c82b8163cb..c0bde74e2c 100644 --- a/test/provider_file_memory_not_impl.cpp +++ b/test/provider_file_memory_not_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2024 Intel Corporation +// Copyright (C) 2024-2025 Intel Corporation // Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception @@ -28,6 +28,6 @@ TEST_F(test, file_provider_not_implemented) { umfFileMemoryProviderParamsSetVisibility(nullptr, UMF_MEM_MAP_PRIVATE); EXPECT_EQ(umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED); - umf_memory_provider_ops_t *ops = umfFileMemoryProviderOps(); + const umf_memory_provider_ops_t *ops = umfFileMemoryProviderOps(); EXPECT_EQ(ops, nullptr); -} \ No newline at end of file +} diff --git a/test/provider_fixed_memory.cpp b/test/provider_fixed_memory.cpp index dac651435a..d9bfc1f709 100644 --- a/test/provider_fixed_memory.cpp +++ b/test/provider_fixed_memory.cpp @@ -38,7 +38,8 @@ static int compare_native_error_str(const char *message, int error) { return strncmp(message, error_str, len); } -using providerCreateExtParams = std::tuple; +using providerCreateExtParams = + std::tuple; static void providerCreateExt(providerCreateExtParams params, umf_test::provider_unique_handle_t *handle) { diff --git a/test/provider_os_memory.cpp b/test/provider_os_memory.cpp index 11a546398b..96396c18f2 100644 --- a/test/provider_os_memory.cpp +++ b/test/provider_os_memory.cpp @@ -44,7 +44,8 @@ static int compare_native_error_str(const char *message, int error) { return strncmp(message, error_str, len); } -using providerCreateExtParams = std::tuple; +using providerCreateExtParams = + std::tuple; static void providerCreateExt(providerCreateExtParams params, umf_test::provider_unique_handle_t *handle) { diff --git a/test/provider_os_memory_not_impl.cpp b/test/provider_os_memory_not_impl.cpp index 13c123fb7e..127ba32e48 100644 --- a/test/provider_os_memory_not_impl.cpp +++ b/test/provider_os_memory_not_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2024 Intel Corporation +// Copyright (C) 2024-2025 Intel Corporation // Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception @@ -41,6 +41,6 @@ TEST_F(test, os_provider_not_implemented) { umf_result = umfOsMemoryProviderParamsSetPartitions(params, partitions, 1); EXPECT_EQ(umf_result, UMF_RESULT_ERROR_NOT_SUPPORTED); - umf_memory_provider_ops_t *ops = umfOsMemoryProviderOps(); + const umf_memory_provider_ops_t *ops = umfOsMemoryProviderOps(); EXPECT_EQ(ops, nullptr); } diff --git a/test/provider_tracking.cpp b/test/provider_tracking.cpp index 55acc452cf..a0ae9955fa 100644 --- a/test/provider_tracking.cpp +++ b/test/provider_tracking.cpp @@ -19,7 +19,8 @@ using umf_test::test; #define FIXED_BUFFER_SIZE (512 * utils_get_page_size()) #define INVALID_PTR ((void *)0x01) -using providerCreateExtParams = std::tuple; +using providerCreateExtParams = + std::tuple; static void providerCreateExt(providerCreateExtParams params, umf_test::provider_unique_handle_t *handle) { diff --git a/test/provider_tracking_fixture_tests.cpp b/test/provider_tracking_fixture_tests.cpp index d81d4f8b1d..8ab7082758 100644 --- a/test/provider_tracking_fixture_tests.cpp +++ b/test/provider_tracking_fixture_tests.cpp @@ -21,11 +21,12 @@ struct provider_from_pool : public umf_test::provider_base_t { umf_memory_pool_handle_t pool; - umf_result_t initialize(umf_memory_pool_handle_t _pool) noexcept { + umf_result_t initialize(const umf_memory_pool_t *_pool) noexcept { if (!_pool) { return UMF_RESULT_ERROR_INVALID_ARGUMENT; } - pool = _pool; + // drop const qualifier + pool = (umf_memory_pool_handle_t)_pool; return UMF_RESULT_SUCCESS; } umf_result_t alloc(size_t size, size_t align, void **ptr) noexcept { diff --git a/test/providers/provider_cuda_not_impl.cpp b/test/providers/provider_cuda_not_impl.cpp index 4054c26a83..9ddea2048c 100644 --- a/test/providers/provider_cuda_not_impl.cpp +++ b/test/providers/provider_cuda_not_impl.cpp @@ -29,6 +29,6 @@ TEST_F(test, cuda_provider_not_implemented) { result = umfCUDAMemoryProviderParamsSetAllocFlags(hParams, 0); ASSERT_EQ(result, UMF_RESULT_ERROR_NOT_SUPPORTED); - umf_memory_provider_ops_t *ops = umfCUDAMemoryProviderOps(); + const umf_memory_provider_ops_t *ops = umfCUDAMemoryProviderOps(); ASSERT_EQ(ops, nullptr); } diff --git a/test/providers/provider_level_zero.cpp b/test/providers/provider_level_zero.cpp index 47b62cc945..e30500d9de 100644 --- a/test/providers/provider_level_zero.cpp +++ b/test/providers/provider_level_zero.cpp @@ -116,7 +116,7 @@ INSTANTIATE_TEST_SUITE_P(, LevelZeroProviderInit, UMF_MEMORY_TYPE_SHARED)); TEST_P(LevelZeroProviderInit, FailNullContext) { - umf_memory_provider_ops_t *ops = umfLevelZeroMemoryProviderOps(); + const umf_memory_provider_ops_t *ops = umfLevelZeroMemoryProviderOps(); ASSERT_NE(ops, nullptr); auto memory_type = GetParam(); @@ -146,7 +146,7 @@ TEST_P(LevelZeroProviderInit, FailNullDevice) { GTEST_SKIP() << "Host memory does not require device handle"; } - umf_memory_provider_ops_t *ops = umfLevelZeroMemoryProviderOps(); + const umf_memory_provider_ops_t *ops = umfLevelZeroMemoryProviderOps(); ASSERT_NE(ops, nullptr); auto memory_type = GetParam(); @@ -171,7 +171,7 @@ TEST_F(LevelZeroProviderInit, FailNonNullDevice) { if (GetParam() != UMF_MEMORY_TYPE_HOST) { GTEST_SKIP() << "Host memory does not require device handle"; } - umf_memory_provider_ops_t *ops = umfLevelZeroMemoryProviderOps(); + const umf_memory_provider_ops_t *ops = umfLevelZeroMemoryProviderOps(); ASSERT_NE(ops, nullptr); auto memory_type = GetParam(); @@ -196,7 +196,7 @@ TEST_F(LevelZeroProviderInit, FailNonNullDevice) { } TEST_F(test, FailMismatchedResidentHandlesCount) { - umf_memory_provider_ops_t *ops = umfLevelZeroMemoryProviderOps(); + const umf_memory_provider_ops_t *ops = umfLevelZeroMemoryProviderOps(); ASSERT_NE(ops, nullptr); umf_level_zero_memory_provider_params_handle_t hParams = nullptr; diff --git a/test/providers/provider_level_zero_not_impl.cpp b/test/providers/provider_level_zero_not_impl.cpp index 4948bd66f1..dfbd4a2b21 100644 --- a/test/providers/provider_level_zero_not_impl.cpp +++ b/test/providers/provider_level_zero_not_impl.cpp @@ -38,6 +38,6 @@ TEST_F(test, level_zero_provider_not_implemented) { result = umfLevelZeroMemoryProviderParamsSetDeviceOrdinal(hParams, 0); ASSERT_EQ(result, UMF_RESULT_ERROR_NOT_SUPPORTED); - umf_memory_provider_ops_t *ops = umfLevelZeroMemoryProviderOps(); + const umf_memory_provider_ops_t *ops = umfLevelZeroMemoryProviderOps(); ASSERT_EQ(ops, nullptr); } diff --git a/test/utils/cpp_helpers.hpp b/test/utils/cpp_helpers.hpp index 037c633c17..e81788ea9f 100644 --- a/test/utils/cpp_helpers.hpp +++ b/test/utils/cpp_helpers.hpp @@ -109,7 +109,7 @@ template umf_memory_pool_ops_t poolMakeCOps() { umf_memory_pool_ops_t ops = detail::poolOpsBase(); ops.initialize = [](umf_memory_provider_handle_t provider, - [[maybe_unused]] void *params, void **obj) { + [[maybe_unused]] const void *params, void **obj) { try { *obj = new T; } catch (...) { @@ -123,7 +123,7 @@ template umf_memory_pool_ops_t poolMakeCOps() { return detail::initialize( reinterpret_cast(*obj), std::make_tuple(provider, - reinterpret_cast(params))); + reinterpret_cast(params))); } }; @@ -137,7 +137,7 @@ template constexpr umf_memory_provider_ops_t providerMakeCOps() { umf_memory_provider_ops_t ops = detail::providerOpsBase(); - ops.initialize = []([[maybe_unused]] void *params, void **obj) { + ops.initialize = []([[maybe_unused]] const void *params, void **obj) { try { *obj = new T; } catch (...) { @@ -150,7 +150,7 @@ constexpr umf_memory_provider_ops_t providerMakeCOps() { } else { return detail::initialize( reinterpret_cast(*obj), - std::make_tuple(reinterpret_cast(params))); + std::make_tuple(reinterpret_cast(params))); } };