Skip to content

Commit

Permalink
[API] Add getVersion function
Browse files Browse the repository at this point in the history
An API has been added to check the version of nntrainer through the
project version of meson build.

Available via ml::train::getVersion.

issue : #2435
Signed-off-by: SeoHyungjun <[email protected]>
  • Loading branch information
SeoHyungjun committed Jan 31, 2024
1 parent 5d0f473 commit 9c83f7a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions api/ccapi/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#if __cplusplus >= MIN_CPP_VERSION

#include <nntrainer-api-common.h>
#include <string>

namespace ml {
namespace train {
Expand All @@ -42,6 +43,11 @@ enum class ExecutionMode {
VALIDATE /** Validate mode, label is necessary */
};

/**
* @brief Get the version of NNTrainer
*/
extern std::string getVersion();

} // namespace train
} // namespace ml

Expand Down
12 changes: 12 additions & 0 deletions api/ccapi/src/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <optimizer.h>
#include <optimizer_wrapped.h>

#include <cstdlib>

namespace ml {
namespace train {

Expand Down Expand Up @@ -138,5 +140,15 @@ createLearningRateScheduler(const std::string &type,
return ac.createObject<ml::train::LearningRateScheduler>(type, properties);
}

std::string getVersion() {
std::string version = std::to_string(VERSION_MAJOR);
version += ".";
version += std::to_string(VERSION_MINOR);
version += ".";
version += std::to_string(VERSION_MICRO);

return version;
}

} // namespace train
} // namespace ml
2 changes: 1 addition & 1 deletion jni/Android.mk.in
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)

LOCAL_ARM_NEON := true
LOCAL_CFLAGS += -pthread -fexceptions -fopenmp -static-openmp @MESON_CFLAGS@ -DML_API_COMMON=1
LOCAL_CXXFLAGS += -std=c++17 -frtti -fexceptions -DML_API_COMMON=1
LOCAL_CXXFLAGS += -std=c++17 -frtti -fexceptions -DML_API_COMMON=1 -DVERSION_MAJOR=@VERSION_MAJOR@ -DVERSION_MINOR=@VERSION_MINOR@ -DVERSION_MICRO=@VERSION_MICRO@
LOCAL_MODULE_TAGS := optional

LOCAL_LDLIBS := -llog -landroid -fopenmp -static-openmp
Expand Down
4 changes: 4 additions & 0 deletions jni/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ and_conf.set('MESON_NNTRAINER_INCS', ' '.join(nntrainer_inc_abs))
and_conf.set('MESON_CCAPI_NNTRAINER_SRCS', ' '.join(ccapi_src))
and_conf.set('MESON_CCAPI_NNTRAINER_INCS', ' '.join(ccapi_inc_abs))

and_conf.set('VERSION_MAJOR', ' '.join(nntrainer_version_split[0]))
and_conf.set('VERSION_MINOR', ' '.join(nntrainer_version_split[1]))
and_conf.set('VERSION_MICRO', ' '.join(nntrainer_version_split[2]))

if get_option('enable-capi').enabled()
and_conf.set('MESON_CAPI_NNTRAINER_SRCS', ' '.join(capi_src))
and_conf.set('MESON_CAPI_NNTRAINER_INCS', ' '.join(capi_inc_abs))
Expand Down
10 changes: 10 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ project('nntrainer', 'c', 'cpp',
'buildtype=release'
]
)

# Set version info
nntrainer_version = meson.project_version()
nntrainer_version_split = nntrainer_version.split('.')

add_project_arguments('-DVERSION="' + nntrainer_version + '"', language: ['c', 'cpp'])
add_project_arguments('-DVERSION_MAJOR=' + nntrainer_version_split[0], language: ['c', 'cpp'])
add_project_arguments('-DVERSION_MINOR=' + nntrainer_version_split[1], language: ['c', 'cpp'])
add_project_arguments('-DVERSION_MICRO=' + nntrainer_version_split[2], language: ['c', 'cpp'])

extra_defines = ['-DMIN_CPP_VERSION=201703L']

cc = meson.get_compiler('c')
Expand Down

0 comments on commit 9c83f7a

Please sign in to comment.