Skip to content

Commit c7b0286

Browse files
authored
Merge pull request #83 from bratpiorka/rrudnick_test_shared_lib_build
add single test for building libumf.so to gha
2 parents 7b28d9d + 85e97af commit c7b0286

File tree

9 files changed

+160
-48
lines changed

9 files changed

+160
-48
lines changed

.github/workflows/basic.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ jobs:
1212
build_type: [Debug, Release]
1313
compiler: [{c: gcc, cxx: g++}]
1414
pool_tracking: ['ON', 'OFF']
15+
shared_library: ['OFF']
1516
include:
1617
- os: 'ubuntu-20.04'
1718
build_type: Release
1819
compiler: {c: gcc-7, cxx: g++-7}
1920
- os: 'ubuntu-22.04'
2021
build_type: Release
21-
compiler: {c: clang, cxx: clang++}
22+
compiler: {c: clang, cxx: clang++}
23+
- os: 'ubuntu-22.04'
24+
build_type: Release
25+
compiler: {c: gcc, cxx: g++}
26+
shared_library: 'ON'
2227
runs-on: ${{matrix.os}}
2328

2429
steps:
@@ -40,6 +45,7 @@ jobs:
4045
cmake
4146
-B ${{github.workspace}}/build
4247
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
48+
-DUMF_BUILD_SHARED_LIBRARY=${{matrix.shared_library}}
4349
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
4450
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
4551
-DUMF_ENABLE_POOL_TRACKING=${{matrix.pool_tracking}}
@@ -66,12 +72,18 @@ jobs:
6672
build_type: [Debug, Release]
6773
compiler: [{c: cl, cxx: cl}]
6874
pool_tracking: ['ON', 'OFF']
75+
shared_library: ['OFF']
6976
include:
7077
- os: 'windows-2022'
7178
build_type: Release
7279
compiler: {c: clang-cl, cxx: clang-cl}
7380
pool_tracking: 'ON'
7481
toolset: "-T ClangCL"
82+
- os: 'windows-2022'
83+
build_type: Release
84+
compiler: {c: cl, cxx: cl}
85+
pool_tracking: 'ON'
86+
shared_library: 'ON'
7587
runs-on: ${{matrix.os}}
7688

7789
steps:
@@ -84,6 +96,7 @@ jobs:
8496
${{matrix.toolset}}
8597
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
8698
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
99+
-DUMF_BUILD_SHARED_LIBRARY=${{matrix.shared_library}}
87100
-DUMF_ENABLE_POOL_TRACKING=${{matrix.pool_tracking}}
88101
-DUMF_FORMAT_CODE_STYLE=OFF
89102
-DUMF_DEVELOPER_MODE=ON

include/umf/base.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
extern "C" {
1818
#endif
1919

20+
#if defined(_WIN32) && defined(UMF_SHARED_LIBRARY)
21+
#define UMF_EXPORT __declspec(dllexport)
22+
#else
23+
#define UMF_EXPORT
24+
#endif
25+
2026
/// @brief Generates generic 'UMF' API versions
2127
#define UMF_MAKE_VERSION(_major, _minor) \
2228
((_major << 16) | (_minor & 0x0000ffff))

include/umf/memory_pool.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,24 @@ typedef struct umf_memory_pool_ops_t umf_memory_pool_ops_t;
3838
/// @param hPool [out] handle to the newly created memory pool
3939
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
4040
///
41-
umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops,
42-
umf_memory_provider_handle_t provider, void *params,
43-
umf_memory_pool_handle_t *hPool);
41+
UMF_EXPORT umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops,
42+
umf_memory_provider_handle_t provider,
43+
void *params,
44+
umf_memory_pool_handle_t *hPool);
4445

4546
///
4647
/// @brief Destroys memory pool.
4748
/// @param hPool handle to the pool
4849
///
49-
void umfPoolDestroy(umf_memory_pool_handle_t hPool);
50+
UMF_EXPORT void umfPoolDestroy(umf_memory_pool_handle_t hPool);
5051

5152
///
5253
/// @brief Allocates \p size bytes of uninitialized storage from \p hPool
5354
/// @param hPool specified memory hPool
5455
/// @param size number of bytes to allocate
5556
/// @return Pointer to the allocated memory.
5657
///
57-
void *umfPoolMalloc(umf_memory_pool_handle_t hPool, size_t size);
58+
UMF_EXPORT void *umfPoolMalloc(umf_memory_pool_handle_t hPool, size_t size);
5859

5960
///
6061
/// @brief Allocates \p size bytes of uninitialized storage from the specified \p hPool
@@ -64,8 +65,8 @@ void *umfPoolMalloc(umf_memory_pool_handle_t hPool, size_t size);
6465
/// @param alignment alignment of the allocation in bytes
6566
/// @return Pointer to the allocated memory
6667
///
67-
void *umfPoolAlignedMalloc(umf_memory_pool_handle_t hPool, size_t size,
68-
size_t alignment);
68+
UMF_EXPORT void *umfPoolAlignedMalloc(umf_memory_pool_handle_t hPool,
69+
size_t size, size_t alignment);
6970

7071
///
7172
/// @brief Allocates memory from \p hPool for an array of \p num elements
@@ -76,7 +77,8 @@ void *umfPoolAlignedMalloc(umf_memory_pool_handle_t hPool, size_t size,
7677
/// @param size number of bytes to allocate for each object
7778
/// @return Pointer to the allocated memory
7879
///
79-
void *umfPoolCalloc(umf_memory_pool_handle_t hPool, size_t num, size_t size);
80+
UMF_EXPORT void *umfPoolCalloc(umf_memory_pool_handle_t hPool, size_t num,
81+
size_t size);
8082

8183
///
8284
/// @brief Reallocates memory from \p hPool
@@ -85,15 +87,17 @@ void *umfPoolCalloc(umf_memory_pool_handle_t hPool, size_t num, size_t size);
8587
/// @param size new size for the memory block in bytes
8688
/// @return Pointer to the allocated memory
8789
///
88-
void *umfPoolRealloc(umf_memory_pool_handle_t hPool, void *ptr, size_t size);
90+
UMF_EXPORT void *umfPoolRealloc(umf_memory_pool_handle_t hPool, void *ptr,
91+
size_t size);
8992

9093
///
9194
/// @brief Obtains size of block of memory allocated from the \p hPool for a given \p ptr
9295
/// @param hPool specified memory hPool
9396
/// @param ptr pointer to the allocated memory
9497
/// @return size of the memory block allocated from the \p hPool
9598
///
96-
size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool, void *ptr);
99+
UMF_EXPORT size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool,
100+
void *ptr);
97101

98102
///
99103
/// @brief Frees the memory space of the specified \p hPool pointed by \p ptr
@@ -103,7 +107,7 @@ size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool, void *ptr);
103107
/// Whether any status other than UMF_RESULT_SUCCESS can be returned
104108
/// depends on the memory provider used by the \p hPool.
105109
///
106-
umf_result_t umfPoolFree(umf_memory_pool_handle_t hPool, void *ptr);
110+
UMF_EXPORT umf_result_t umfPoolFree(umf_memory_pool_handle_t hPool, void *ptr);
107111

108112
///
109113
/// @brief Frees the memory space pointed by ptr if it belongs to UMF pool, does nothing otherwise.
@@ -112,7 +116,7 @@ umf_result_t umfPoolFree(umf_memory_pool_handle_t hPool, void *ptr);
112116
/// Whether any status other than UMF_RESULT_SUCCESS can be returned
113117
/// depends on the memory provider used by the pool.
114118
///
115-
umf_result_t umfFree(void *ptr);
119+
UMF_EXPORT umf_result_t umfFree(void *ptr);
116120

117121
///
118122
/// @brief Retrieve \p umf_result_t representing the error of the last failed allocation
@@ -132,15 +136,16 @@ umf_result_t umfFree(void *ptr);
132136
/// @return Error code desciribng the failure of the last failed allocation operation.
133137
/// The value is undefined if the previous allocation was successful.
134138
///
135-
umf_result_t umfPoolGetLastAllocationError(umf_memory_pool_handle_t hPool);
139+
UMF_EXPORT umf_result_t
140+
umfPoolGetLastAllocationError(umf_memory_pool_handle_t hPool);
136141

137142
///
138143
/// @brief Retrieve memory pool associated with a given ptr. Only memory allocated
139144
/// with the usage of a memory provider is being tracked.
140145
/// @param ptr pointer to memory belonging to a memory pool
141146
/// @return Handle to a memory pool that contains ptr or NULL if pointer does not belong to any UMF pool.
142147
///
143-
umf_memory_pool_handle_t umfPoolByPtr(const void *ptr);
148+
UMF_EXPORT umf_memory_pool_handle_t umfPoolByPtr(const void *ptr);
144149

145150
///
146151
/// @brief Retrieve memory provider associated with a given pool.
@@ -149,8 +154,8 @@ umf_memory_pool_handle_t umfPoolByPtr(const void *ptr);
149154
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
150155
/// UMF_RESULT_ERROR_INVALID_ARGUMENT if hProvider is NULL
151156
///
152-
umf_result_t umfPoolGetMemoryProvider(umf_memory_pool_handle_t hPool,
153-
umf_memory_provider_handle_t *hProvider);
157+
UMF_EXPORT umf_result_t umfPoolGetMemoryProvider(
158+
umf_memory_pool_handle_t hPool, umf_memory_provider_handle_t *hProvider);
154159

155160
#ifdef __cplusplus
156161
}

include/umf/memory_provider.h

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ typedef struct umf_memory_provider_t *umf_memory_provider_handle_t;
2727
/// @param hProvider [out] pointer to the newly created memory provider
2828
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
2929
///
30-
umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
31-
void *params,
32-
umf_memory_provider_handle_t *hProvider);
30+
UMF_EXPORT umf_result_t
31+
umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops, void *params,
32+
umf_memory_provider_handle_t *hProvider);
3333

3434
///
3535
/// @brief Destroys memory provider.
3636
/// @param hProvider handle to the memory provider
3737
///
38-
void umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider);
38+
UMF_EXPORT void
39+
umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider);
3940

4041
///
4142
/// @brief Allocates \p size bytes of uninitialized storage from memory \p hProvider
@@ -46,8 +47,9 @@ void umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider);
4647
/// @param ptr [out] pointer to the allocated memory
4748
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
4849
///
49-
umf_result_t umfMemoryProviderAlloc(umf_memory_provider_handle_t hProvider,
50-
size_t size, size_t alignment, void **ptr);
50+
UMF_EXPORT umf_result_t
51+
umfMemoryProviderAlloc(umf_memory_provider_handle_t hProvider, size_t size,
52+
size_t alignment, void **ptr);
5153

5254
///
5355
/// @brief Frees the memory space pointed by \p ptr from the memory \p hProvider
@@ -56,8 +58,8 @@ umf_result_t umfMemoryProviderAlloc(umf_memory_provider_handle_t hProvider,
5658
/// @param size size of the allocation
5759
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
5860
///
59-
umf_result_t umfMemoryProviderFree(umf_memory_provider_handle_t hProvider,
60-
void *ptr, size_t size);
61+
UMF_EXPORT umf_result_t umfMemoryProviderFree(
62+
umf_memory_provider_handle_t hProvider, void *ptr, size_t size);
6163

6264
///
6365
/// @brief Retrieve string representation of the underlying provider specific
@@ -83,9 +85,9 @@ umf_result_t umfMemoryProviderFree(umf_memory_provider_handle_t hProvider,
8385
/// result in string representation
8486
/// @param pError [out] pointer to an integer where the adapter specific error code will be stored
8587
///
86-
void umfMemoryProviderGetLastNativeError(umf_memory_provider_handle_t hProvider,
87-
const char **ppMessage,
88-
int32_t *pError);
88+
UMF_EXPORT void
89+
umfMemoryProviderGetLastNativeError(umf_memory_provider_handle_t hProvider,
90+
const char **ppMessage, int32_t *pError);
8991

9092
///
9193
/// @brief Retrieve recommended page size for a given allocation size.
@@ -94,9 +96,8 @@ void umfMemoryProviderGetLastNativeError(umf_memory_provider_handle_t hProvider,
9496
/// @param pageSize [out] pointer to the recommended page size
9597
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
9698
///
97-
umf_result_t
98-
umfMemoryProviderGetRecommendedPageSize(umf_memory_provider_handle_t hProvider,
99-
size_t size, size_t *pageSize);
99+
UMF_EXPORT umf_result_t umfMemoryProviderGetRecommendedPageSize(
100+
umf_memory_provider_handle_t hProvider, size_t size, size_t *pageSize);
100101

101102
///
102103
/// @brief Retrieve minimum possible page size used by memory region referenced by a given \p ptr
@@ -106,9 +107,8 @@ umfMemoryProviderGetRecommendedPageSize(umf_memory_provider_handle_t hProvider,
106107
/// @param pageSize [out] pointer to the minimum possible page size
107108
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
108109
///
109-
umf_result_t
110-
umfMemoryProviderGetMinPageSize(umf_memory_provider_handle_t hProvider,
111-
void *ptr, size_t *pageSize);
110+
UMF_EXPORT umf_result_t umfMemoryProviderGetMinPageSize(
111+
umf_memory_provider_handle_t hProvider, void *ptr, size_t *pageSize);
112112

113113
///
114114
/// @brief Discard physical pages within the virtual memory mapping associated at the given addr
@@ -120,8 +120,8 @@ umfMemoryProviderGetMinPageSize(umf_memory_provider_handle_t hProvider,
120120
/// UMF_RESULT_ERROR_INVALID_ALIGNMENT if ptr or size is not page-aligned.
121121
/// UMF_RESULT_ERROR_NOT_SUPPORTED if operation is not supported by this provider.
122122
///
123-
umf_result_t umfMemoryProviderPurgeLazy(umf_memory_provider_handle_t hProvider,
124-
void *ptr, size_t size);
123+
UMF_EXPORT umf_result_t umfMemoryProviderPurgeLazy(
124+
umf_memory_provider_handle_t hProvider, void *ptr, size_t size);
125125

126126
///
127127
/// @brief Discard physical pages within the virtual memory mapping associated at the given addr and \p size.
@@ -133,15 +133,16 @@ umf_result_t umfMemoryProviderPurgeLazy(umf_memory_provider_handle_t hProvider,
133133
/// UMF_RESULT_ERROR_INVALID_ALIGNMENT if ptr or size is not page-aligned.
134134
/// UMF_RESULT_ERROR_NOT_SUPPORTED if operation is not supported by this provider.
135135
///
136-
umf_result_t umfMemoryProviderPurgeForce(umf_memory_provider_handle_t hProvider,
137-
void *ptr, size_t size);
136+
UMF_EXPORT umf_result_t umfMemoryProviderPurgeForce(
137+
umf_memory_provider_handle_t hProvider, void *ptr, size_t size);
138138

139139
///
140140
/// @brief Retrieve name of a given memory \p hProvider.
141141
/// @param hProvider handle to the memory provider
142142
/// @return pointer to a string containing the name of the \p hProvider
143143
///
144-
const char *umfMemoryProviderGetName(umf_memory_provider_handle_t hProvider);
144+
UMF_EXPORT const char *
145+
umfMemoryProviderGetName(umf_memory_provider_handle_t hProvider);
145146

146147
///
147148
/// @brief Retrieve handle to the last memory provider that returned status other
@@ -153,7 +154,7 @@ const char *umfMemoryProviderGetName(umf_memory_provider_handle_t hProvider);
153154
///
154155
/// @return Handle to the memory provider
155156
///
156-
umf_memory_provider_handle_t umfGetLastFailedMemoryProvider(void);
157+
UMF_EXPORT umf_memory_provider_handle_t umfGetLastFailedMemoryProvider(void);
157158

158159
#ifdef __cplusplus
159160
}

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set(UMF_SOURCES_LINUX
2020
)
2121

2222
set(UMF_SOURCES_WINDOWS
23+
provider/provider_os_memory_windows.c
2324
provider/provider_tracking_windows.cpp
2425
utils/utils_windows_concurrency.c
2526
utils/utils_windows_math.c
@@ -50,6 +51,8 @@ if(UMF_BUILD_SHARED_LIBRARY)
5051
SRCS ${UMF_SOURCES}
5152
LIBS ${UMF_LIBS})
5253
target_compile_definitions(umf PUBLIC UMF_SHARED_LIBRARY)
54+
set_target_properties(umf PROPERTIES
55+
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_UMF_OUTPUT_DIRECTORY})
5356
else()
5457
add_umf_library(NAME umf
5558
TYPE STATIC

src/memory_pool_internal.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ typedef struct umf_memory_pool_t {
3131
bool own_provider;
3232
} umf_memory_pool_t;
3333

34-
umf_result_t umfPoolCreateEx(const umf_memory_pool_ops_t *pool_ops,
35-
void *pool_params,
36-
const umf_memory_provider_ops_t *provider_ops,
37-
void *provider_params,
38-
umf_memory_pool_handle_t *hPool);
34+
UMF_EXPORT umf_result_t
35+
umfPoolCreateEx(const umf_memory_pool_ops_t *pool_ops, void *pool_params,
36+
const umf_memory_provider_ops_t *provider_ops,
37+
void *provider_params, umf_memory_pool_handle_t *hPool);
3938

4039
#ifdef __cplusplus
4140
}

src/provider/provider_os_memory_linux.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ static int os_translate_purge_advise(umf_purge_advise_t advise) {
105105
return -1;
106106
}
107107

108-
long os_mbind(void *addr, unsigned long len, int mode,
109-
const unsigned long *nodemask, unsigned long maxnode,
110-
unsigned flags) {
108+
long os_mbind(void *addr, size_t len, int mode, const unsigned long *nodemask,
109+
unsigned long maxnode, unsigned flags) {
111110
return mbind(addr, len, mode, nodemask, maxnode, flags);
112111
}
113112

0 commit comments

Comments
 (0)