Skip to content

Commit 61fe479

Browse files
notoraptorabergeron
authored andcommitted
Add ABI version handling in C code and Python code (#323)
* Add GPUARRAY_ABI_VERSION constant and pygpu.gpuarray.abi_version() method. A new header file (abi_version.h) auto-generated by CMake has been added. * Add auto-generated file `src/gpuarray/abi_version.h` to .gitignore. * Make GPUARRAY_ABI_VERSION a number (1000*major + minor) Change ABI minor version (1.0 -> 1.1) to make some tests. * Add auto-generated CMake SOVERSION variable (equals to the first part of VERSION). Now the built library file is named libgpuarray.so.SOVERSION, that is libgpuarray.so.ABIMAJOR. * Back to right current version.
1 parent 9efa493 commit 61fe479

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ distribute*tar.gz
2020
pygpu/*.c
2121
pygpu/*.h
2222
pygpu/version.py
23+
src/gpuarray/abi_version.h
2324
src/private_config.h
2425
Makefile.conf

pygpu/gpuarray.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ cdef extern from "Python.h":
2323

2424
cdef extern from "gpuarray/config.h":
2525
int GPUARRAY_API_VERSION
26+
int GPUARRAY_ABI_VERSION
2627

2728
cdef extern from "gpuarray/types.h":
2829
ctypedef struct gpuarray_type:

pygpu/gpuarray.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ def api_version():
1313
# (library version, module version)
1414
return (GPUARRAY_API_VERSION, 0)
1515

16+
def abi_version():
17+
major_version = GPUARRAY_ABI_VERSION / 1000
18+
minor_version = GPUARRAY_ABI_VERSION % 1000
19+
return (major_version, minor_version)
20+
1621
np.import_array()
1722

1823
# to export the numeric value

src/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,27 @@ add_library(gpuarray-static STATIC ${GPUARRAY_SRC})
9696
target_link_libraries(gpuarray ${CMAKE_DL_LIBS})
9797
target_link_libraries(gpuarray-static ${CMAKE_DL_LIBS})
9898

99+
# Generate gpuarray/abi_version.h that contains the ABI version number.
100+
get_target_property(GPUARRAY_ABI_VERSION gpuarray VERSION)
101+
string(REPLACE "." ";" GPUARRAY_ABI_VERSION_NUMBERS ${GPUARRAY_ABI_VERSION})
102+
list(GET GPUARRAY_ABI_VERSION_NUMBERS 0 GPUARRAY_ABI_VERSION_MAJOR)
103+
list(GET GPUARRAY_ABI_VERSION_NUMBERS 1 GPUARRAY_ABI_VERSION_MINOR)
104+
math(EXPR GPUARRAY_ABI_NUMBER "1000*${GPUARRAY_ABI_VERSION_MAJOR} + ${GPUARRAY_ABI_VERSION_MINOR}")
105+
FILE(WRITE gpuarray/abi_version.h
106+
"\#ifndef GPUARRAY_ABI_VERSION\n\#define GPUARRAY_ABI_VERSION ${GPUARRAY_ABI_NUMBER}\n\#endif\n"
107+
)
108+
109+
# set SOVERSION and ensure it is the first part of VERSION.
110+
set_property(TARGET gpuarray PROPERTY SOVERSION ${GPUARRAY_ABI_VERSION_MAJOR})
111+
99112
set(headers
100113
gpuarray/array.h
101114
gpuarray/blas.h
102115
gpuarray/collectives.h
103116
gpuarray/buffer.h
104117
gpuarray/buffer_blas.h
105118
gpuarray/buffer_collectives.h
119+
gpuarray/abi_version.h
106120
gpuarray/config.h
107121
gpuarray/elemwise.h
108122
gpuarray/error.h

src/gpuarray/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef GPUARRAY_CONFIG
22
#define GPUARRAY_CONFIG
33

4+
/* The following included file should have been generated by CMake. */
5+
#include <gpuarray/abi_version.h>
46
#define GPUARRAY_API_VERSION 0
57

68
#ifdef GPUARRAY_SHARED

0 commit comments

Comments
 (0)