質問編集履歴

4

コードのURLと変更箇所の追記

2020/12/20 13:32

投稿

shosin__
shosin__

スコア6

test CHANGED
File without changes
test CHANGED
@@ -54,306 +54,40 @@
54
54
 
55
55
 
56
56
 
57
- ・setup.pyのコード
57
+ 参考コードのURL
58
58
 
59
- ```python
60
-
61
- import numpy as np
62
-
63
- import os
64
-
65
- from os.path import join as pjoin
66
-
67
- #from distutils.core import setup
68
-
69
- from setuptools import setup
70
-
71
- from distutils.extension import Extension
72
-
73
- from Cython.Distutils import build_ext
59
+ https://github.com/qijiezhao/M2Det
74
-
75
- import subprocess
76
60
 
77
61
 
78
62
 
79
- #change for windows, by MrX
63
+ 変更箇所
80
64
 
81
- nvcc_bin = 'nvcc.exe'
65
+ ・setup.py
82
66
 
67
+  61行目を変更
68
+
69
+  変更前:for k, v in cudaconfig.iteritems():
70
+
83
- lib_dir = 'lib/x64'
71
+  変更後:for k, v in cudaconfig.items():
84
72
 
85
73
 
86
74
 
87
- def find_in_path(name, path):
88
-
89
- "Find a file in a search path"
90
-
91
- # Adapted fom
75
+  128~136行目をコメントアウト
92
-
93
- # http://code.activestate.com/recipes/52224-find-a-file-given-a-search-path/
94
-
95
- for dir in path.split(os.pathsep):
96
-
97
- binpath = pjoin(dir, name)
98
-
99
- if os.path.exists(binpath):
100
-
101
- return os.path.abspath(binpath)
102
-
103
- return None
104
76
 
105
77
 
106
78
 
79
+ ・setup_cuda.py
107
80
 
81
+  61行目を変更
108
82
 
109
- def locate_cuda():
83
+  変更前:nvcc_compile_args = ['-O', '--ptxas-options=-v', '-arch=sm_35', '-c', '--compiler-options=-fPIC']
110
84
 
111
- """Locate the CUDA environment on the system
85
+  変更後:nvcc_compile_args = ['-O2', '--ptxas-options=-v', '-arch=sm_35', '-c', '--compiler-options=-fPIC']
112
86
 
113
87
 
114
88
 
115
- Returns a dict with keys 'home', 'nvcc', 'include', and 'lib64'
89
+  100行目と101行目の間に以下を追記
116
90
 
117
- and values giving the absolute path to each directory.
91
+    #Remove ',ID=2'
118
92
 
119
-
120
-
121
- Starts by looking for the CUDAHOME env variable. If not found, everything
122
-
123
- is based on finding 'nvcc' in the PATH.
124
-
125
- """
126
-
127
-
128
-
129
- # first check if the CUDAHOME env variable is in use
130
-
131
- if 'CUDA_PATH' in os.environ:
93
+ elif ',ID=2' in c: cmd[idx] = c[0:len(c)-5]
132
-
133
- home = os.environ['CUDA_PATH']
134
-
135
- print("home = %s\n" % home)
136
-
137
- nvcc = pjoin(home, 'bin', nvcc_bin)
138
-
139
- else:
140
-
141
- # otherwise, search the PATH for NVCC
142
-
143
- default_path = pjoin(os.sep, 'usr', 'local', 'cuda', 'bin')
144
-
145
- nvcc = find_in_path(nvcc_bin, os.environ['PATH'] + os.pathsep + default_path)
146
-
147
- if nvcc is None:
148
-
149
- raise EnvironmentError('The nvcc binary could not be '
150
-
151
- 'located in your $PATH. Either add it to your path, or set $CUDA_PATH')
152
-
153
- home = os.path.dirname(os.path.dirname(nvcc))
154
-
155
- print("home = %s, nvcc = %s\n" % (home, nvcc))
156
-
157
-
158
-
159
- cudaconfig = {'home':home, 'nvcc':nvcc,
160
-
161
- 'include': pjoin(home, 'include'),
162
-
163
- 'lib64': pjoin(home, lib_dir)}
164
-
165
- # for k, v in cudaconfig.iteritems():
166
-
167
- for k, v in cudaconfig.items():
168
-
169
- if not os.path.exists(v):
170
-
171
- raise EnvironmentError('The CUDA %s path could not be located in %s' % (k, v))
172
-
173
- return cudaconfig
174
-
175
- CUDA = locate_cuda()
176
-
177
- # Obtain the numpy include directory. This logic works across numpy versions.
178
-
179
- try:
180
-
181
- numpy_include = np.get_include()
182
-
183
- except AttributeError:
184
-
185
- numpy_include = np.get_numpy_include()
186
-
187
-
188
-
189
-
190
-
191
- def customize_compiler_for_nvcc(self):
192
-
193
- """inject deep into distutils to customize how the dispatch
194
-
195
- to gcc/nvcc works.
196
-
197
-
198
-
199
- If you subclass UnixCCompiler, it's not trivial to get your subclass
200
-
201
- injected in, and still have the right customizations (i.e.
202
-
203
- distutils.sysconfig.customize_compiler) run on it. So instead of going
204
-
205
- the OO route, I have this. Note, it's kindof like a wierd functional
206
-
207
- subclassing going on."""
208
-
209
-
210
-
211
- # tell the compiler it can processes .cu
212
-
213
- #self.src_extensions.append('.cu')
214
-
215
-
216
-
217
-
218
-
219
- # save references to the default compiler_so and _comple methods
220
-
221
- #default_compiler_so = self.spawn
222
-
223
- #default_compiler_so = self.rc
224
-
225
- super = self.compile
226
-
227
-
228
-
229
- # now redefine the _compile method. This gets executed for each
230
-
231
- # object but distutils doesn't have the ability to change compilers
232
-
233
- # based on source extension: we add it.
234
-
235
- def compile(sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, depends=None):
236
-
237
- postfix=os.path.splitext(sources[0])[1]
238
-
239
-
240
-
241
- if postfix == '.cu':
242
-
243
- # use the cuda for .cu files
244
-
245
- #self.set_executable('compiler_so', CUDA['nvcc'])
246
-
247
- # use only a subset of the extra_postargs, which are 1-1 translated
248
-
249
- # from the extra_compile_args in the Extension class
250
-
251
- postargs = extra_postargs['nvcc']
252
-
253
- else:
254
-
255
- postargs = extra_postargs['gcc']
256
-
257
- return super(sources, output_dir, macros, include_dirs, debug, extra_preargs, postargs, depends)
258
-
259
- # reset the default compiler_so, which we might have changed for cuda
260
-
261
- #self.rc = default_compiler_so
262
-
263
-
264
-
265
- # inject our redefined _compile method into the class
266
-
267
- self.compile = compile
268
-
269
- # run the customize_compiler
270
-
271
- class custom_build_ext(build_ext):
272
-
273
- def build_extensions(self):
274
-
275
- customize_compiler_for_nvcc(self.compiler)
276
-
277
- build_ext.build_extensions(self)
278
-
279
- ext_modules = [
280
-
281
- # unix _compile: obj, src, ext, cc_args, extra_postargs, pp_opts
282
-
283
- Extension(
284
-
285
- "utils.cython_bbox",
286
-
287
- sources=["utils\bbox.pyx"],
288
-
289
- #define_macros={'/LD'},
290
-
291
- #extra_compile_args={'gcc': ['/link', '/DLL', '/OUT:cython_bbox.dll']},
292
-
293
- #extra_compile_args={'gcc': ['/LD']},
294
-
295
- extra_compile_args={'gcc': []},
296
-
297
- include_dirs = [numpy_include]
298
-
299
- ),
300
-
301
- Extension(
302
-
303
- "nms.cpu_nms",
304
-
305
- sources=["nms\cpu_nms.pyx"],
306
-
307
- extra_compile_args={'gcc': []},
308
-
309
- include_dirs = [numpy_include],
310
-
311
- ),
312
-
313
- Extension(
314
-
315
- "pycocotools._mask",
316
-
317
- sources=['pycocotools\maskApi.c', 'pycocotools\_mask.pyx'],
318
-
319
- include_dirs = [numpy_include, 'pycocotools'],
320
-
321
- extra_compile_args={
322
-
323
- 'gcc': ['/Qstd=c99']},
324
-
325
- ),
326
-
327
- #Extension( # just used to get nms\gpu_nms.obj
328
-
329
- # "nms.gpu_nms",
330
-
331
- # sources=['nms\gpu_nms.pyx'],
332
-
333
- # language='c++',
334
-
335
- # extra_compile_args={'gcc': []},
336
-
337
- # include_dirs = [numpy_include]
338
-
339
- #),
340
-
341
- ]
342
-
343
-
344
-
345
- setup(
346
-
347
- name='fast_rcnn',
348
-
349
- ext_modules=ext_modules,
350
-
351
- # inject our custom trigger
352
-
353
- cmdclass={'build_ext': custom_build_ext},
354
-
355
- )
356
-
357
-
358
-
359
- ```

3

コード編集

2020/12/20 13:32

投稿

shosin__
shosin__

スコア6

test CHANGED
File without changes
test CHANGED
@@ -56,8 +56,6 @@
56
56
 
57
57
  ・setup.pyのコード
58
58
 
59
-
60
-
61
59
  ```python
62
60
 
63
61
  import numpy as np
@@ -355,3 +353,7 @@
355
353
  cmdclass={'build_ext': custom_build_ext},
356
354
 
357
355
  )
356
+
357
+
358
+
359
+ ```

2

コードを追加

2020/12/19 22:30

投稿

shosin__
shosin__

スコア6

test CHANGED
File without changes
test CHANGED
@@ -51,3 +51,307 @@
51
51
  というエラーが出ました。
52
52
 
53
53
  初心者なので、できるだけわかりやすく教えていただけると幸いです。
54
+
55
+
56
+
57
+ ・setup.pyのコード
58
+
59
+
60
+
61
+ ```python
62
+
63
+ import numpy as np
64
+
65
+ import os
66
+
67
+ from os.path import join as pjoin
68
+
69
+ #from distutils.core import setup
70
+
71
+ from setuptools import setup
72
+
73
+ from distutils.extension import Extension
74
+
75
+ from Cython.Distutils import build_ext
76
+
77
+ import subprocess
78
+
79
+
80
+
81
+ #change for windows, by MrX
82
+
83
+ nvcc_bin = 'nvcc.exe'
84
+
85
+ lib_dir = 'lib/x64'
86
+
87
+
88
+
89
+ def find_in_path(name, path):
90
+
91
+ "Find a file in a search path"
92
+
93
+ # Adapted fom
94
+
95
+ # http://code.activestate.com/recipes/52224-find-a-file-given-a-search-path/
96
+
97
+ for dir in path.split(os.pathsep):
98
+
99
+ binpath = pjoin(dir, name)
100
+
101
+ if os.path.exists(binpath):
102
+
103
+ return os.path.abspath(binpath)
104
+
105
+ return None
106
+
107
+
108
+
109
+
110
+
111
+ def locate_cuda():
112
+
113
+ """Locate the CUDA environment on the system
114
+
115
+
116
+
117
+ Returns a dict with keys 'home', 'nvcc', 'include', and 'lib64'
118
+
119
+ and values giving the absolute path to each directory.
120
+
121
+
122
+
123
+ Starts by looking for the CUDAHOME env variable. If not found, everything
124
+
125
+ is based on finding 'nvcc' in the PATH.
126
+
127
+ """
128
+
129
+
130
+
131
+ # first check if the CUDAHOME env variable is in use
132
+
133
+ if 'CUDA_PATH' in os.environ:
134
+
135
+ home = os.environ['CUDA_PATH']
136
+
137
+ print("home = %s\n" % home)
138
+
139
+ nvcc = pjoin(home, 'bin', nvcc_bin)
140
+
141
+ else:
142
+
143
+ # otherwise, search the PATH for NVCC
144
+
145
+ default_path = pjoin(os.sep, 'usr', 'local', 'cuda', 'bin')
146
+
147
+ nvcc = find_in_path(nvcc_bin, os.environ['PATH'] + os.pathsep + default_path)
148
+
149
+ if nvcc is None:
150
+
151
+ raise EnvironmentError('The nvcc binary could not be '
152
+
153
+ 'located in your $PATH. Either add it to your path, or set $CUDA_PATH')
154
+
155
+ home = os.path.dirname(os.path.dirname(nvcc))
156
+
157
+ print("home = %s, nvcc = %s\n" % (home, nvcc))
158
+
159
+
160
+
161
+ cudaconfig = {'home':home, 'nvcc':nvcc,
162
+
163
+ 'include': pjoin(home, 'include'),
164
+
165
+ 'lib64': pjoin(home, lib_dir)}
166
+
167
+ # for k, v in cudaconfig.iteritems():
168
+
169
+ for k, v in cudaconfig.items():
170
+
171
+ if not os.path.exists(v):
172
+
173
+ raise EnvironmentError('The CUDA %s path could not be located in %s' % (k, v))
174
+
175
+ return cudaconfig
176
+
177
+ CUDA = locate_cuda()
178
+
179
+ # Obtain the numpy include directory. This logic works across numpy versions.
180
+
181
+ try:
182
+
183
+ numpy_include = np.get_include()
184
+
185
+ except AttributeError:
186
+
187
+ numpy_include = np.get_numpy_include()
188
+
189
+
190
+
191
+
192
+
193
+ def customize_compiler_for_nvcc(self):
194
+
195
+ """inject deep into distutils to customize how the dispatch
196
+
197
+ to gcc/nvcc works.
198
+
199
+
200
+
201
+ If you subclass UnixCCompiler, it's not trivial to get your subclass
202
+
203
+ injected in, and still have the right customizations (i.e.
204
+
205
+ distutils.sysconfig.customize_compiler) run on it. So instead of going
206
+
207
+ the OO route, I have this. Note, it's kindof like a wierd functional
208
+
209
+ subclassing going on."""
210
+
211
+
212
+
213
+ # tell the compiler it can processes .cu
214
+
215
+ #self.src_extensions.append('.cu')
216
+
217
+
218
+
219
+
220
+
221
+ # save references to the default compiler_so and _comple methods
222
+
223
+ #default_compiler_so = self.spawn
224
+
225
+ #default_compiler_so = self.rc
226
+
227
+ super = self.compile
228
+
229
+
230
+
231
+ # now redefine the _compile method. This gets executed for each
232
+
233
+ # object but distutils doesn't have the ability to change compilers
234
+
235
+ # based on source extension: we add it.
236
+
237
+ def compile(sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, depends=None):
238
+
239
+ postfix=os.path.splitext(sources[0])[1]
240
+
241
+
242
+
243
+ if postfix == '.cu':
244
+
245
+ # use the cuda for .cu files
246
+
247
+ #self.set_executable('compiler_so', CUDA['nvcc'])
248
+
249
+ # use only a subset of the extra_postargs, which are 1-1 translated
250
+
251
+ # from the extra_compile_args in the Extension class
252
+
253
+ postargs = extra_postargs['nvcc']
254
+
255
+ else:
256
+
257
+ postargs = extra_postargs['gcc']
258
+
259
+ return super(sources, output_dir, macros, include_dirs, debug, extra_preargs, postargs, depends)
260
+
261
+ # reset the default compiler_so, which we might have changed for cuda
262
+
263
+ #self.rc = default_compiler_so
264
+
265
+
266
+
267
+ # inject our redefined _compile method into the class
268
+
269
+ self.compile = compile
270
+
271
+ # run the customize_compiler
272
+
273
+ class custom_build_ext(build_ext):
274
+
275
+ def build_extensions(self):
276
+
277
+ customize_compiler_for_nvcc(self.compiler)
278
+
279
+ build_ext.build_extensions(self)
280
+
281
+ ext_modules = [
282
+
283
+ # unix _compile: obj, src, ext, cc_args, extra_postargs, pp_opts
284
+
285
+ Extension(
286
+
287
+ "utils.cython_bbox",
288
+
289
+ sources=["utils\bbox.pyx"],
290
+
291
+ #define_macros={'/LD'},
292
+
293
+ #extra_compile_args={'gcc': ['/link', '/DLL', '/OUT:cython_bbox.dll']},
294
+
295
+ #extra_compile_args={'gcc': ['/LD']},
296
+
297
+ extra_compile_args={'gcc': []},
298
+
299
+ include_dirs = [numpy_include]
300
+
301
+ ),
302
+
303
+ Extension(
304
+
305
+ "nms.cpu_nms",
306
+
307
+ sources=["nms\cpu_nms.pyx"],
308
+
309
+ extra_compile_args={'gcc': []},
310
+
311
+ include_dirs = [numpy_include],
312
+
313
+ ),
314
+
315
+ Extension(
316
+
317
+ "pycocotools._mask",
318
+
319
+ sources=['pycocotools\maskApi.c', 'pycocotools\_mask.pyx'],
320
+
321
+ include_dirs = [numpy_include, 'pycocotools'],
322
+
323
+ extra_compile_args={
324
+
325
+ 'gcc': ['/Qstd=c99']},
326
+
327
+ ),
328
+
329
+ #Extension( # just used to get nms\gpu_nms.obj
330
+
331
+ # "nms.gpu_nms",
332
+
333
+ # sources=['nms\gpu_nms.pyx'],
334
+
335
+ # language='c++',
336
+
337
+ # extra_compile_args={'gcc': []},
338
+
339
+ # include_dirs = [numpy_include]
340
+
341
+ #),
342
+
343
+ ]
344
+
345
+
346
+
347
+ setup(
348
+
349
+ name='fast_rcnn',
350
+
351
+ ext_modules=ext_modules,
352
+
353
+ # inject our custom trigger
354
+
355
+ cmdclass={'build_ext': custom_build_ext},
356
+
357
+ )

1

コードを追記しました。

2020/12/19 22:29

投稿

shosin__
shosin__

スコア6

test CHANGED
File without changes
test CHANGED
File without changes