@@ -54,6 +54,25 @@ def get_minor():
54
54
def get_patch():
55
55
return str(_get_version_detail(2))
56
56
57
+ def get_cuda_version():
58
+ if '@WITH_GPU@' == 'ON':
59
+ return '@CUDA_VERSION@'
60
+ else:
61
+ return 'False'
62
+
63
+ def get_cudnn_version():
64
+ if '@WITH_GPU@' == 'ON':
65
+ temp_cudnn_version = ''
66
+ if '@CUDNN_MAJOR_VERSION@':
67
+ temp_cudnn_version += '@CUDNN_MAJOR_VERSION@'
68
+ if '@CUDNN_MINOR_VERSION@':
69
+ temp_cudnn_version += '.@CUDNN_MINOR_VERSION@'
70
+ if '@CUDNN_PATCHLEVEL_VERSION@':
71
+ temp_cudnn_version += '.@CUDNN_PATCHLEVEL_VERSION@'
72
+ return temp_cudnn_version
73
+ else:
74
+ return 'False'
75
+
57
76
def is_taged():
58
77
try:
59
78
cmd = ['git', 'describe', '--exact-match', '--tags', 'HEAD', '2>/dev/null']
@@ -67,18 +86,22 @@ def is_taged():
67
86
else:
68
87
return False
69
88
70
- def write_version_py(filename='paddle/version.py'):
89
+ def write_version_py(filename='paddle/version/__init__ .py'):
71
90
cnt = '''# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY
72
91
#
73
92
full_version = '%(major)d.%(minor)d.%(patch)s'
74
93
major = '%(major)d'
75
94
minor = '%(minor)d'
76
95
patch = '%(patch)s'
77
96
rc = '%(rc)d'
97
+ cuda_version = '%(cuda)s'
98
+ cudnn_version = '%(cudnn)s'
78
99
istaged = %(istaged)s
79
100
commit = '%(commit)s'
80
101
with_mkl = '%(with_mkl)s'
81
102
103
+ __all__ = ['cuda', 'cudnn']
104
+
82
105
def show():
83
106
if istaged:
84
107
print('full_version:', full_version)
@@ -91,20 +114,65 @@ def show():
91
114
92
115
def mkl():
93
116
return with_mkl
117
+
118
+ def cuda():
119
+ """Get cuda version of paddle package.
120
+
121
+ Returns:
122
+ string: Return the version information of cuda. If paddle package is CPU version, it will return False.
123
+
124
+ Examples:
125
+ .. code-block:: python
126
+
127
+ import paddle
128
+
129
+ paddle.version.cuda()
130
+ # '10.2'
131
+
132
+ """
133
+ return cuda_version
134
+
135
+ def cudnn():
136
+ """Get cudnn version of paddle package.
137
+
138
+ Returns:
139
+ string: Return the version information of cudnn. If paddle package is CPU version, it will return False.
140
+
141
+ Examples:
142
+ .. code-block:: python
143
+
144
+ import paddle
145
+
146
+ paddle.version.cudnn()
147
+ # '7.6.5'
148
+
149
+ """
150
+ return cudnn_version
94
151
'''
95
152
commit = git_commit()
153
+
154
+ dirname = os.path.dirname(filename)
155
+
156
+ try:
157
+ os.makedirs(dirname)
158
+ except OSError as e:
159
+ if e.errno != errno.EEXIST:
160
+ raise
161
+
96
162
with open(filename, 'w') as f:
97
163
f.write(cnt % {
98
164
'major': get_major(),
99
165
'minor': get_minor(),
100
166
'patch': get_patch(),
101
167
'rc': RC,
102
168
'version': '${PADDLE_VERSION}',
169
+ 'cuda': get_cuda_version(),
170
+ 'cudnn': get_cudnn_version(),
103
171
'commit': commit,
104
172
'istaged': is_taged(),
105
173
'with_mkl': '@WITH_MKL@'})
106
174
107
- write_version_py(filename='@PADDLE_BINARY_DIR@/python/paddle/version.py')
175
+ write_version_py(filename='@PADDLE_BINARY_DIR@/python/paddle/version/__init__ .py')
108
176
109
177
def write_cuda_env_config_py(filename='paddle/cuda_env.py'):
110
178
cnt = ""
@@ -251,6 +319,7 @@ packages=['paddle',
251
319
'paddle.autograd',
252
320
'paddle.device',
253
321
'paddle.device.cuda',
322
+ 'paddle.version',
254
323
]
255
324
256
325
with open('@PADDLE_SOURCE_DIR@/python/requirements.txt') as f:
0 commit comments