jheymann85 / chainer_ctc

8 stars 8 forks source link

New Setup for independent execution #3

Open Fhrozen opened 5 years ago

Fhrozen commented 5 years ago

For espnet the requirement to add libwarpctc.so to LD is quite troublesome. I just finished some test after adding some lines and didnot find any trouble:

import numpy
from setuptools import setup, Extension
import os
import platform
import shutil

warp_ctc_libpath = "./chainer_ctc/lib"
warp_ctc_build_path = "./ext/warp-ctc/build"

include_dirs = [os.path.realpath('./ext/warp-ctc/include')]
if platform.system() == 'Darwin':
    lib_ext = ".dylib"
else:
    lib_ext = ".so"
warp_ctc_libname = 'libwarpctc{}'.format(lib_ext)

if not os.path.isdir(warp_ctc_libpath):
    os.makedirs(warp_ctc_libpath)
shutil.copyfile(
    '{}/{}'.format(warp_ctc_build_path, warp_ctc_libname),
    '{}/{}'.format(warp_ctc_libpath, warp_ctc_libname)
)

setup(
    name="chainer_ctc",
    version="1.0",
    description="Fast CTC for Chainer + wrapper for Baidus warp-ctc",
    platforms=['Linux'],
    classifiers=[
        'Intended Audience :: Developers',
        'License :: OSI Approved :: BSD License',
        'Operating System :: POSIX :: Linux',
    ],
    author="Jahn Heymann",
    packages=['chainer_ctc', 'chainer_ctc.src', ],
    author_email="jahnheymann@gmail.com",
    include_package_data=True,
    package_data={'chainer_ctc': [os.path.realpath('{}/{}'.format(warp_ctc_libpath, warp_ctc_libname))]},
    setup_requires=['setuptools_cython', 'Cython >= 0.18'],
    ext_modules=[
        Extension('chainer_ctc.src.ctc_cpu', ["chainer_ctc/src/ctc_cpu.pyx"],
                  include_dirs=[numpy.get_include()],
                  language='c++'),
        Extension('chainer_ctc.src.warp_ctc',
                  ["chainer_ctc/src/warp_ctc.pyx"],
                  include=[numpy.get_include(),
                           'ctc.h'],
                  libraries=['warpctc'],
                  include_dirs=include_dirs,
                  library_dirs=[os.path.realpath(warp_ctc_libpath)],
                  extra_link_args=['-Wl,-rpath,' + os.path.realpath(warp_ctc_libpath)],
                  language='c++')
    ]
)

this will required to install the package using: python setup.py install and with no longer required to add the lib to LD @sw005320 , @jheymann85

Let me know if is fine or not.

jheymann85 commented 5 years ago

Hi Fhrozen, thanks for the suggestion. Lifting the requirement to add the lib would indeed be a nice improvement. I won't be able to test it until next week and will comment once I was able to do so. Do you think there is a way to achieve the same without breaking the pip install ... functionality?

Fhrozen commented 5 years ago

I tested with both python setup and pip install and found no problem only need to remove from the previous code the lines:

include_package_data=True,
    package_data={'chainer_ctc': [os.path.realpath('{}/{}'.format(warp_ctc_libpath, warp_ctc_libname))]},

the setup.py will link the warp_ctc to the one located at '{}/{}'.format(warp_ctc_libpath, warp_ctc_libname)

I was trying to move link to that would be storage at site-packages/ but could not achieved. Still missing a flag maybe in the setup, but I do not have time to test now.