From 903ed4e6d47c640f8fff5eeb0c71966908998f5a Mon Sep 17 00:00:00 2001 From: Krystian Chmielewski Date: Fri, 18 Dec 2020 12:14:58 +0100 Subject: [PATCH] add ocloc versioning Adds versioning of ocloc and new api function returning ocloc version. --- .../unit_test/offline_compiler/ocloc_api_tests.cpp | 4 ++++ shared/offline_compiler/source/ocloc_api.cpp | 4 ++++ shared/offline_compiler/source/ocloc_api.h | 14 ++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/opencl/test/unit_test/offline_compiler/ocloc_api_tests.cpp b/opencl/test/unit_test/offline_compiler/ocloc_api_tests.cpp index b9de7a763d..415288977f 100644 --- a/opencl/test/unit_test/offline_compiler/ocloc_api_tests.cpp +++ b/opencl/test/unit_test/offline_compiler/ocloc_api_tests.cpp @@ -19,6 +19,10 @@ extern Environment *gEnvironment; using namespace std::string_literals; +TEST(OclocApiTests, WhenOclocVersionIsCalledThenCurrentOclocVersionIsReturned) { + EXPECT_EQ(ocloc_version_t::OCLOC_VERSION_CURRENT, oclocVersion()); +} + TEST(OclocApiTests, WhenGoodArgsAreGivenThenSuccessIsReturned) { const char *argv[] = { "ocloc", diff --git a/shared/offline_compiler/source/ocloc_api.cpp b/shared/offline_compiler/source/ocloc_api.cpp index d2534fbc10..44299ea07b 100644 --- a/shared/offline_compiler/source/ocloc_api.cpp +++ b/shared/offline_compiler/source/ocloc_api.cpp @@ -149,4 +149,8 @@ int oclocFreeOutput(uint32_t *numOutputs, uint8_t ***dataOutputs, uint64_t **len delete[](*nameOutputs); return 0; } + +int oclocVersion() { + return static_cast(ocloc_version_t::OCLOC_VERSION_CURRENT); +} } diff --git a/shared/offline_compiler/source/ocloc_api.h b/shared/offline_compiler/source/ocloc_api.h index cf586e7508..4db6b5bf10 100644 --- a/shared/offline_compiler/source/ocloc_api.h +++ b/shared/offline_compiler/source/ocloc_api.h @@ -7,6 +7,17 @@ #include +#ifndef OCLOC_MAKE_VERSION +/// Generates ocloc API versions +#define OCLOC_MAKE_VERSION(_major, _minor) ((_major << 16) | (_minor & 0x0000ffff)) +#endif // OCLOC_MAKE_VERSION + +typedef enum _ocloc_version_t { + OCLOC_VERSION_1_0 = OCLOC_MAKE_VERSION(1, 0), ///< version 1.0 + OCLOC_VERSION_CURRENT = OCLOC_MAKE_VERSION(1, 0), ///< latest known version + OCLOC_VERSION_FORCE_UINT32 = 0x7fffffff +} ocloc_version_t; + #ifdef _WIN32 #define SIGNATURE __declspec(dllexport) int __cdecl #else @@ -82,4 +93,7 @@ SIGNATURE oclocInvoke(unsigned int numArgs, const char *argv[], /// /// \returns 0 on succes. Returns non-0 in case of failure. SIGNATURE oclocFreeOutput(uint32_t *numOutputs, uint8_t ***dataOutputs, uint64_t **lenOutputs, char ***nameOutputs); + +/// Returns the current version of oclock +SIGNATURE oclocVersion(); }