cuda.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2010
  4. "cuda"
  5. import os
  6. from waflib import Task
  7. from waflib.TaskGen import extension
  8. from waflib.Tools import ccroot, c_preproc
  9. from waflib.Configure import conf
  10. class cuda(Task.Task):
  11. run_str = '${NVCC} ${CUDAFLAGS} ${CXXFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CXX_SRC_F}${SRC} ${CXX_TGT_F} ${TGT}'
  12. color = 'GREEN'
  13. ext_in = ['.h']
  14. vars = ['CCDEPS']
  15. scan = c_preproc.scan
  16. shell = False
  17. @extension('.cu', '.cuda')
  18. def c_hook(self, node):
  19. return self.create_compiled_task('cuda', node)
  20. def configure(conf):
  21. conf.find_program('nvcc', var='NVCC')
  22. conf.find_cuda_libs()
  23. @conf
  24. def find_cuda_libs(self):
  25. """
  26. find the cuda include and library folders
  27. use ctx.program(source='main.c', target='app', use='CUDA CUDART')
  28. """
  29. if not self.env.NVCC:
  30. self.fatal('check for nvcc first')
  31. d = self.root.find_node(self.env.NVCC[0]).parent.parent
  32. node = d.find_node('include')
  33. _includes = node and node.abspath() or ''
  34. _libpath = []
  35. for x in ('lib64', 'lib'):
  36. try:
  37. _libpath.append(d.find_node(x).abspath())
  38. except:
  39. pass
  40. # this should not raise any error
  41. self.check_cxx(header='cuda.h', lib='cuda', libpath=_libpath, includes=_includes)
  42. self.check_cxx(header='cuda.h', lib='cudart', libpath=_libpath, includes=_includes)