Skip to content

Commit

Permalink
fix ctypes usage
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Mar 26, 2024
1 parent c588a74 commit 6577d4f
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/Python/ccpi/filters/utils.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
import platform
import ctypes
import os
import warnings

if platform.system() == 'Linux':
dll = 'libcilreg.so'
elif platform.system() == 'Windows':
dll_file = 'cilreg.dll'
dll = ctypes.util.find_library(dll_file)
elif platform.system() == 'Darwin':
dll = 'libcilreg.dylib'
else:
raise ValueError('Not supported platform, ', platform.system())
try:
pre = {'Linux': 'lib', 'Windows': '', 'Darwin': 'lib'}[platform.system()]
ext = {'Linux': '.so', 'Windows': '.dll', 'Darwin': '.dylib'}[platform.system()]
except KeyError:
raise ValueError(f"unsupported platform: {platform.system()}")

cilreg = ctypes.cdll.LoadLibrary(os.path.join(os.path.dirname(__file__), dll))
_here = os.path.dirname(__file__)
dll = f'{pre}cilreg{ext}'
cilreg = ctypes.cdll.LoadLibrary(os.path.join(_here, dll))

gpudll = f'{pre}cilregcuda{ext}'
try:
if platform.system() == 'Linux':
gpudll = 'libcilregcuda.so'
elif platform.system() == 'Windows':
gpudll_file = 'cilregcuda.dll'
gpudll = ctypes.util.find_library(gpudll_file)
elif platform.system() == 'Darwin':
gpudll = 'libcilregcuda.dylib'
else:
raise ValueError('Not supported platform, ', platform.system())

cilregcuda = ctypes.cdll.LoadLibrary(os.path.join(os.path.dirname(__file__), gpudll))
except OSError as ose:
print(ose)
cilregcuda = ctypes.cdll.LoadLibrary(os.path.join(_here, gpudll))
except OSError as exc:
warnings.warn(str(exc), ImportWarning, stacklevel=2)
cilregcuda = None

0 comments on commit 6577d4f

Please sign in to comment.