Skip to content

Commit c78f929

Browse files
fix OpenCL driver version calculation
Related-To: NEO-5626 Signed-off-by: Artur Harasimiuk <[email protected]>
1 parent 3bbbe9f commit c78f929

File tree

2 files changed

+56
-16
lines changed

2 files changed

+56
-16
lines changed

scripts/neo_ww_calculator.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (C) 2021 Intel Corporation
4+
#
5+
# SPDX-License-Identifier: MIT
6+
#
7+
8+
import sys
9+
10+
from datetime import datetime, timezone
11+
12+
def convert_ww(epoch):
13+
dt = datetime.fromtimestamp(epoch, timezone.utc)
14+
15+
# get some info from epoch
16+
yr = int(dt.strftime("%y"))
17+
doy = int(dt.strftime("%j"))
18+
# and day of week for Jan 1st
19+
dow1 = int(datetime(dt.year, 1, 1).strftime("%w"))
20+
21+
# number of days in a year
22+
_is_leap = yr % 400 == 0 or (yr % 4 == 0 and yr % 100 != 0)
23+
_y_days = 366 if _is_leap else 365
24+
25+
_doy = doy - 1 + dow1 # shift day of year to simulate Jan 1st as Sunday
26+
_ww = int(_doy / 7) + 1 # get workweek
27+
_wd = int(_doy % 7) # get days of week
28+
_y_days = _y_days + dow1 # adjusted number of days in year
29+
_w_days = _y_days - _doy + _wd # numer of week days days to end of year
30+
31+
if _w_days < 7:
32+
# last week has less than 7 days
33+
yr = yr + 1
34+
_ww = 1
35+
36+
print("{:02d}.{:02d}".format(yr, _ww))
37+
return 0
38+
39+
if __name__ == '__main__':
40+
exit(convert_ww(int(sys.argv[1])))

version.cmake

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
#
2-
# Copyright (C) 2018-2020 Intel Corporation
2+
# Copyright (C) 2018-2021 Intel Corporation
33
#
44
# SPDX-License-Identifier: MIT
55
#
66

77
if(UNIX)
88
if(NOT DEFINED NEO_OCL_DRIVER_VERSION)
99
find_program(GIT NAMES git)
10-
if(NOT "${GIT}" STREQUAL "GIT-NOTFOUND")
10+
find_program(PYTHON_EXECUTABLE NAMES "python3")
11+
if((NOT "${GIT}" STREQUAL "GIT-NOTFOUND") AND (NOT "${PYTHON_EXECUTABLE}" STREQUAL "PYTHON_EXECUTABLE-NOTFOUND"))
1112
if(IS_DIRECTORY ${NEO_SOURCE_DIR}/.git)
1213
set(GIT_arg --git-dir=${NEO_SOURCE_DIR}/.git show -s --format=%ct)
1314
execute_process(
1415
COMMAND ${GIT} ${GIT_arg}
1516
OUTPUT_VARIABLE GIT_output
1617
OUTPUT_STRIP_TRAILING_WHITESPACE
1718
)
19+
set(PYTHON_arg ${CMAKE_CURRENT_SOURCE_DIR}/scripts/neo_ww_calculator.py ${GIT_output})
20+
execute_process(
21+
COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_arg}
22+
OUTPUT_VARIABLE VERSION_output
23+
OUTPUT_STRIP_TRAILING_WHITESPACE
24+
)
25+
string(REPLACE "." ";" VERSION_list ${VERSION_output})
1826
endif()
27+
else()
28+
message(WARNING "Unable to determine OpenCL major.minor version. Defaulting to 1.0")
1929
endif()
2030

2131
if(NOT DEFINED NEO_OCL_VERSION_MAJOR)
22-
if(NOT DEFINED GIT_output)
32+
if(NOT DEFINED VERSION_list)
2333
set(NEO_OCL_VERSION_MAJOR 1)
2434
else()
25-
SET(DATE_arg --date=@${GIT_output} +%y)
26-
execute_process(
27-
COMMAND date ${DATE_arg}
28-
OUTPUT_VARIABLE NEO_OCL_VERSION_MAJOR
29-
OUTPUT_STRIP_TRAILING_WHITESPACE
30-
)
35+
list(GET VERSION_list 0 NEO_OCL_VERSION_MAJOR)
3136
message(STATUS "Computed OpenCL version major is: ${NEO_OCL_VERSION_MAJOR}")
3237
endif()
3338
endif()
3439

3540
if(NOT DEFINED NEO_OCL_VERSION_MINOR)
36-
if(NOT DEFINED GIT_output)
41+
if(NOT DEFINED VERSION_list)
3742
set(NEO_OCL_VERSION_MINOR 0)
3843
else()
39-
SET(DATE_arg --date=@${GIT_output} +%V)
40-
execute_process(
41-
COMMAND date ${DATE_arg}
42-
OUTPUT_VARIABLE NEO_OCL_VERSION_MINOR
43-
OUTPUT_STRIP_TRAILING_WHITESPACE
44-
)
44+
list(GET VERSION_list 1 NEO_OCL_VERSION_MINOR)
4545
message(STATUS "Computed OpenCL version minor is: ${NEO_OCL_VERSION_MINOR}")
4646
endif()
4747
endif()

0 commit comments

Comments
 (0)