Skip to content

Commit

Permalink
fix pyilmbase tests, static compilation
Browse files Browse the repository at this point in the history
- python extensions must be shared, so can not follow the overall lib
type for the library.
- the code should be compiled fPIC when building a static library such
that it can be linked into a .so
- remove the dependency on the particle python extension in the numpy
test
- add environment variables such that the python tests will work in the
build tree without a "make install" (win32 doesn't neede
ld_library_path, but it doesn't hurt, but may need path?)

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
  • Loading branch information
kdt3rd authored and nickrasmussen committed Aug 9, 2018
1 parent 4481442 commit 75c918b
Show file tree
Hide file tree
Showing 10 changed files with 585 additions and 619 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ if ((OPENEXR_BUILD_UTILS OR OPENEXR_BUILD_TESTS OR OPENEXR_BUILD_VIEWERS) AND NO
endif()
endif()

# Set position independent code (mostly for static builds, but not a bad idea regardless)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Perform the build
if(OPENEXR_BUILD_ILMBASE)
add_subdirectory(IlmBase)
Expand Down
2 changes: 2 additions & 0 deletions PyIlmBase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ IF (OPENEXR_BUILD_SHARED)
IF (WIN32)
ADD_DEFINITIONS(-DOPENEXR_DLL)
ENDIF ()
ELSE (OPENEXR_BUILD_SHARED)
SET (LIB_TYPE STATIC)
ENDIF (OPENEXR_BUILD_SHARED)

LINK_DIRECTORIES ( ${ILMBASE_PACKAGE_PREFIX}/lib )
Expand Down
6 changes: 3 additions & 3 deletions PyIlmBase/PyIex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ INSTALL (
include/OpenEXR
)


ADD_LIBRARY ( iexmodule ${LIB_TYPE}
# must be shared
ADD_LIBRARY ( iexmodule SHARED
iexmodule.cpp
)

Expand All @@ -59,6 +59,6 @@ TARGET_LINK_LIBRARIES ( iexmodule
SET_ILMBASE_INCLUDE_DIRS( iexmodule )

INSTALL ( TARGETS iexmodule
DESTINATION lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages
DESTINATION lib/python${OPENEXR_PYTHON_MAJOR}.${OPENEXR_PYTHON_MINOR}/site-packages
)

4 changes: 3 additions & 1 deletion PyIlmBase/PyIexTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ADD_TEST ( PyIexTest
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyIexTest.in
)
)

SET_TESTS_PROPERTIES ( PyIexTest PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/../PyIex;LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../IlmBase/Iex:${CMAKE_CURRENT_BINARY_DIR}/../PyIex" )
5 changes: 3 additions & 2 deletions PyIlmBase/PyImath/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ INSTALL (DIRECTORY ./
FILES_MATCHING PATTERN "*.h"
)

ADD_LIBRARY ( imathmodule ${LIB_TYPE}
# must be shared
ADD_LIBRARY ( imathmodule SHARED
imathmodule.cpp
PyImathFun.cpp
PyImathBasicTypes.cpp
Expand Down Expand Up @@ -93,6 +94,6 @@ TARGET_LINK_LIBRARIES ( imathmodule
)

INSTALL ( TARGETS imathmodule
DESTINATION lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages
DESTINATION lib/python${OPENEXR_PYTHON_MAJOR}.${OPENEXR_PYTHON_MINOR}/site-packages
)

5 changes: 3 additions & 2 deletions PyIlmBase/PyImathNumpy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

ADD_LIBRARY ( imathnumpymodule ${LIB_TYPE}
# must be shared
ADD_LIBRARY ( imathnumpymodule SHARED
imathnumpymodule.cpp
)

Expand Down Expand Up @@ -30,6 +31,6 @@ TARGET_LINK_LIBRARIES ( imathnumpymodule
)

INSTALL ( TARGETS imathnumpymodule
DESTINATION lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages
DESTINATION lib/python${OPENEXR_PYTHON_MAJOR}.${OPENEXR_PYTHON_MINOR}/site-packages
)

6 changes: 4 additions & 2 deletions PyIlmBase/PyImathNumpyTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ADD_TEST ( PyImathMumpyTest
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyImathMumpyTest.in
ADD_TEST ( PyImathNumpyTest
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyImathNumpyTest.in -nocuda
)

SET_TESTS_PROPERTIES ( PyImathNumpyTest PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/../PyIex:${CMAKE_CURRENT_BINARY_DIR}/../PyImath:${CMAKE_CURRENT_BINARY_DIR}/../PyImathNumpy;LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../IlmBase/Iex:${CMAKE_CURRENT_BINARY_DIR}/../../IlmBase/IexMath:${CMAKE_CURRENT_BINARY_DIR}/../../IlmBase/Imath:${CMAKE_CURRENT_BINARY_DIR}/../PyIex:${CMAKE_CURRENT_BINARY_DIR}/../PyImath:${CMAKE_CURRENT_BINARY_DIR}/../PyImathNumpy" )
81 changes: 20 additions & 61 deletions PyIlmBase/PyImathNumpyTest/pyImathNumpyTest.in
Original file line number Diff line number Diff line change
@@ -1,74 +1,33 @@
import sys

if len(sys.argv) != 2 or sys.argv[1] not in ['-cuda','-nocuda']:
print "Usage: %s <-cuda|-nocuda>" % (sys.argv[0])
sys.exit(1)

use_cuda = False
if sys.argv[1] == '-cuda':
use_cuda = True

if use_cuda:
import pycuda.autoinit
import pycuda.driver as drv
from pycuda.compiler import SourceModule
mod = SourceModule("""
__global__ void multiply_them(float *dest, float *a, float *b)
{
const int i = threadIdx.x;
dest[i] = a[i] * b[i];
}
__global__ void multiply_them_int(int *dest, int *a, int *b)
{
const int i = threadIdx.x;
dest[i] = a[i] * b[i];
}
""")
multiply_them = mod.get_function("multiply_them")
multiply_them_int = mod.get_function("multiply_them_int")
from __future__ import print_function

import sys
import numpy
import imathnumpy
from imath import FloatArray, IntArray
import particle

length = 10
fa = particle.random(1,5,length)
fb = particle.random(1,5,length)
a = numpy.random.uniform(1,5,length)
b = numpy.random.uniform(1,5,length)
fdest = FloatArray(length)

a = imathnumpy.arrayToNumpy(fa)
b = imathnumpy.arrayToNumpy(fb)
dest = imathnumpy.arrayToNumpy(fdest)
dest[:] = a * b

if use_cuda:
multiply_them(drv.Out(dest), drv.In(a), drv.In(b), block=(length,1,1))
else:
dest[:] = a * b
results = fdest - a*b

results = fdest - fa*fb
print( "a: {}".format(a) )
print( "b: {}".format(b) )
print( "dest: {}".format(fdest) )
print( "diff: {}".format(results) )

print "a:", particle.join(fa,' ')
print "b:", particle.join(fb,' ')
print "dest:", particle.join(fdest,' ')
print "diff:", particle.join(results,' ')

ia = particle.floor(particle.random(1,5,length))
ib = particle.floor(particle.random(1,5,length))
ia = numpy.floor(numpy.random.uniform(1,5,length))
ib = numpy.floor(numpy.random.uniform(1,5,length))
idest = IntArray(length)

a = imathnumpy.arrayToNumpy(ia)
b = imathnumpy.arrayToNumpy(ib)
dest = imathnumpy.arrayToNumpy(idest)

if use_cuda:
multiply_them_int(drv.Out(dest), drv.In(a), drv.In(b), block=(length,1,1))
else:
dest[:] = a * b

results = idest - ia*ib

print "a:", particle.join(ia,' ')
print "b:", particle.join(ib,' ')
print "dest:", particle.join(idest,' ')
print "diff:", particle.join(results,' ')
idest = imathnumpy.arrayToNumpy(idest)
idest[:] = ia * ib
iresults = idest - ia*ib

print( "a: {}".format(ia) )
print( "b: {}".format(ib) )
print( "dest: {}".format(idest) )
print( "diff: {}".format(iresults) )
2 changes: 2 additions & 0 deletions PyIlmBase/PyImathTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ADD_TEST ( PyImathTest
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pyImathTest.in
)

SET_TESTS_PROPERTIES ( PyImathTest PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/../PyIex:${CMAKE_CURRENT_BINARY_DIR}/../PyImath;LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../IlmBase/Iex:${CMAKE_CURRENT_BINARY_DIR}/../../IlmBase/IexMath:${CMAKE_CURRENT_BINARY_DIR}/../../IlmBase/Imath:${CMAKE_CURRENT_BINARY_DIR}/../PyIex:${CMAKE_CURRENT_BINARY_DIR}/../PyImath" )
Loading

0 comments on commit 75c918b

Please sign in to comment.