Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0e68809
Have algebra extension compiling and not segfaulting.
maureendaum Apr 19, 2019
219ebef
Can load, encode, and save video.
maureendaum Apr 25, 2019
c57f8b6
wip
maureendaum May 17, 2019
6fd1b89
wip: selection
maureendaum May 29, 2019
f4f3682
working python except map
maureendaum Jun 6, 2019
988772c
wip: more python stuff
maureendaum Jun 9, 2019
434bcc5
wip
maureendaum Jun 19, 2019
c53e035
pranay branch
Feb 9, 2020
2dede26
merged changes
mundrapranay Feb 9, 2020
242a3f5
volume, options
mundrapranay Mar 9, 2020
829f038
optionsmap
mundrapranay Mar 20, 2020
8609a99
some progress on Catalog
mundrapranay Apr 3, 2020
18f2a4c
remove build directory
mundrapranay Apr 5, 2020
541ba35
python library working
mundrapranay May 7, 2020
d81b2d8
deleted extra comments
mundrapranay May 7, 2020
c7a0260
GOP done, deleted dashtranscoder.cc
mundrapranay May 7, 2020
d0c46aa
code cleanup done
mundrapranay May 14, 2020
ab30969
change in namespace
mundrapranay May 14, 2020
7bcb70b
code cleanup
mundrapranay May 15, 2020
f76f67b
final changes
mundrapranay May 15, 2020
a46ab1e
PyOptions updated
mundrapranay May 16, 2020
8d7db64
removed tmp
mundrapranay May 16, 2020
693a786
Final cleanup
BrandonHaynes May 18, 2020
e8bd9c5
merge
mundrapranay Jun 4, 2020
5ebe19d
pranayUDF2
mundrapranay Jun 5, 2020
ccf86c9
segmentation fault debugging
mundrapranay Jun 15, 2020
c0426df
python greyscale UDF
mundrapranay Jun 18, 2020
244ed09
python lambda
mundrapranay Jun 18, 2020
2c04eff
removed tmp folder
mundrapranay Jun 18, 2020
207128c
Merge branch 'master' into pranayUDF2
BrandonHaynes Jun 29, 2020
883bf72
PR changes done
mundrapranay Jul 19, 2020
6702dcd
PR changes done
mundrapranay Jul 19, 2020
3a70b76
PR done
mundrapranay Aug 11, 2020
0dcec19
unit test pylightdb done
mundrapranay Nov 19, 2020
fe9f502
unit test pylightdb done
mundrapranay Nov 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions cmake/Modules/FindIPP.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Find the Intel IPP (Integrated Performance Primitives)
#
# IPP_FOUND - System has IPP
# IPP_INCLUDE_DIRS - IPP include files directories
# IPP_LIBRARIES - The IPP libraries
#
# The environment variable IPPROOT is used to find the installation location.
# If the environment variable is not set we'll look for it in the default installation locations.
#
# Usage:
#
# find_package(IPP)
# if(IPP_FOUND)
# target_link_libraries(TARGET ${IPP_LIBRARIES})
# endif()

find_path(IPP_ROOT_DIR
include/ipp.h
PATHS
$ENV{IPPROOT}
/opt/intel/compilers_and_libraries/linux/ipp
/opt/intel/compilers_and_libraries/mac/ipp
"C:/IntelSWTools/compilers_and_libraries/windows/ipp/"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/ipp"
$ENV{HOME}/intel/ipp
$ENV{HOME}/miniconda3
$ENV{USERPROFILE}/miniconda3/Library
"C:/Miniconda37-x64/Library" # Making AppVeyor happy
)

find_path(IPP_INCLUDE_DIR
ipp.h
PATHS
${IPP_ROOT_DIR}/include
)

if(WIN32)
set(IPP_SEARCH_LIB ippcoremt.lib)
set(IPP_LIBS ippcoremt.lib ippsmt.lib ippdcmt.lib)
elseif(APPLE)
set(IPP_SEARCH_LIB libippcore.a)
set(IPP_LIBS libipps.a libippdc.a libippcore.a)
else() # Linux
set(IPP_SEARCH_LIB libippcore.so)
set(IPP_LIBS ipps ippdc ippcore)
endif()


find_path(IPP_LIB_SEARCHPATH
${IPP_SEARCH_LIB}
PATHS
${IPP_ROOT_DIR}/lib/intel64
${IPP_ROOT_DIR}/lib
)

foreach(LIB ${IPP_LIBS})
find_library(${LIB}_PATH ${LIB} PATHS ${IPP_LIB_SEARCHPATH})
if(${LIB}_PATH)
set(IPP_LIBRARIES ${IPP_LIBRARIES} ${${LIB}_PATH})
set(IPP_FOUND TRUE)
else()
# message(STATUS "Could not find ${LIB}: disabling IPP")
set(IPP_NOTFOUND TRUE)
endif()
endforeach()

if(IPP_FOUND AND NOT IPP_NOTFOUND)
set(IPP_INCLUDE_DIRS ${IPP_INCLUDE_DIR})
include_directories(${IPP_INCLUDE_DIRS})
message(STATUS "Found IPP libraries in: ${IPP_LIBRARIES}")
else()
message(STATUS "No IPP libraries found.")
set(IPP_FOUND FALSE)
endif()
11 changes: 7 additions & 4 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ file(GLOB LIGHTDB_CORE_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/../core/*/include/")
include_directories(${LIGHTDB_CORE_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${Python2_INCLUDE_DIRS})

# Include ipp
include_directories(/opt/intel/ipp/include)
link_directories(/opt/intel/ipp/lib/intel64)
#include_directories(/opt/intel/ipp/include)
#link_directories(/opt/intel/ipp/lib/intel64)
FIND_PACKAGE (IPP REQUIRED )
include_directories ( ${IPP_INCLUDE_DIRS} )
link_directories ( ${IPP_LIBRARIES} )

# Include python header files
file(GLOB LIGHTDB_PYTHON_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/../python/include")
Expand All @@ -31,7 +34,7 @@ set(LIGHTDB_SOURCES ${LIGHTDB_PYTHON_SOURCES})
add_library(pylightdb SHARED ${LIGHTDB_PYTHON_SOURCES})
target_compile_options(pylightdb PRIVATE "-fvisibility=default")


target_link_libraries(pylightdb ${Boost_LIBRARIES} ${Python2_LIBRARIES} lightdb_shared)
#target_link_libraries(pylightdb ${Boost_LIBRARIES} ${Python2_LIBRARIES} ${LIGHTDB_LIB_DEPENDENCIES} lightdb_protobuf lightdb_shared)
target_link_libraries(pylightdb opencv_core ippi ippcc boost_numpy)
target_link_libraries(pylightdb opencv_core ${IPP_LIB_I} ${IPP_LIB_CC} boost_numpy)
set_target_properties(pylightdb PROPERTIES PREFIX "")
1 change: 0 additions & 1 deletion python/include/PythonLightField.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ namespace lightdb::python {
PythonLightField Union(boost::python::list &listOfLightFields);
PythonLightField Discretize(lightdb::Dimension dimension, double interval);
PythonLightField Interpolate(lightdb::Dimension dimension);
PythonLightField Map(PyObject *udf, const std::filesystem::path &path);
PythonLightField Map(const lightdb::functor::unaryfunctor &functor);
PythonLightField Encode();
PythonLightField Save(const std::string &filename);
Expand Down
23 changes: 13 additions & 10 deletions python/include/PythonGreyscale.h → python/include/PythonUnary.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#ifndef LIGHTDB_PYTHON_GREYSCALE_H
#define LIGHTDB_PYTHON_GREYSCALE_H
#ifndef LIGHTDB_PYTHON_UNARY_H
#define LIGHTDB_PYTHON_UNARY_H


#include "ipp.h"
#include "Functor.h"
#include <Python.h>


namespace lightdb::python {
class PythonGreyscale : public lightdb::functor::unaryfunctor {
class PythonUnary : public lightdb::functor::unaryfunctor {
class CPU : public lightdb::functor::unaryfunction {
public:
explicit CPU(PyObject* const callable, const bool deterministic=true)
Expand All @@ -15,33 +18,33 @@ namespace lightdb::python {
callable_(callable)
{
CHECK_NOTNULL(callable);
callable->ob_refcnt++;
callable->ob_refcnt++;
// boost::python::incref(callable.ptr());
}

void Allocate(const unsigned int height, const unsigned int width, const unsigned int channels) {
if (rgbSize_ != channels * height * width) {
frameSize_ = height * width;
rgbSize_ = channels * frameSize_;
rgb_.resize(rgbSize_);
mask_.resize(rgbSize_);
}
}

void nv12ToRgb(auto& frame, auto y_in, auto uv_in, const auto channels, const IppiSize& size);

lightdb::shared_reference<lightdb::LightField> operator()(lightdb::LightField& field) override;

private:
PyObject* const callable_;
unsigned int kernelSize_;
unsigned int rgbSize_;
unsigned int frameSize_;
std::vector<unsigned char> rgb_;
std::vector<unsigned char> mask_;
std::vector<unsigned char> rgb_;
};

public:
explicit PythonGreyscale(PyObject* const callable, const bool deterministic=true) : functor::unaryfunctor("Greyscale", CPU(callable, deterministic)) {}
explicit PythonUnary(PyObject* const callable, const bool deterministic=true) : functor::unaryfunctor("Unary", CPU(callable, deterministic)) {}
};

}

#endif //LIGHTDB__PYTHON_GREYSCALE_H
#endif //LIGHTDB__PYTHON_UNARY_H
6 changes: 2 additions & 4 deletions python/src/Module.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "PythonLightField.h"
#include "PythonGeometry.h"
#include "PythonGreyscale.h"
#include "PythonUnary.h"
#include <boost/python.hpp>


Expand All @@ -27,7 +27,6 @@ namespace lightdb::python {
.def("Union", static_cast<PythonLightField(PythonLightField::*)(boost::python::list&)>(&PythonLightField::Union))
.def("Discretize", &PythonLightField::Discretize)
.def("Interpolate", &PythonLightField::Interpolate)
.def("Map", static_cast<PythonLightField(PythonLightField::*)(PyObject*, const std::filesystem::path&)>(&PythonLightField::Map))
.def("Map", static_cast<PythonLightField(PythonLightField::*)(const lightdb::functor::unaryfunctor&)>(&PythonLightField::Map))
.def("Encode", &PythonLightField::Encode)
.def("Save", &PythonLightField::Save)
Expand Down Expand Up @@ -81,8 +80,7 @@ namespace lightdb::python {
boost::python::class_<lightdb::interpolation::Linear>("Linear");

boost::python::class_<lightdb::functor::naryfunctor<1>>("UnaryFunctor", boost::python::no_init);
boost::python::class_<class lightdb::Greyscale, boost::python::bases<lightdb::functor::unaryfunctor>>("Greyscale");
boost::python::class_<PythonGreyscale, boost::shared_ptr<PythonGreyscale>, boost::python::bases<lightdb::functor::unaryfunctor>>("PythonGreyscale", boost::python::init<PyObject*>())
boost::python::class_<PythonUnary, boost::shared_ptr<PythonUnary>, boost::python::bases<lightdb::functor::unaryfunctor>>("PythonUnary", boost::python::init<PyObject*>())
.def(boost::python::init<PyObject*, bool>());
boost::python::class_<typename lightdb::options<>>("PyOptions", boost::python::no_init);
};
Expand Down
6 changes: 0 additions & 6 deletions python/src/PythonLightField.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ namespace lightdb::python {
return PythonLightField(_lightField.Interpolate(dimension, lightdb::interpolation::Linear()));
}

//TODO : Expose UDFs
PythonLightField PythonLightField::Map(PyObject *udf, const std::filesystem::path &path) {
auto yolo = lightdb::extensibility::Load("yolo", path);
return PythonLightField(_lightField.Map(yolo));
}

PythonLightField PythonLightField::Map(const lightdb::functor::unaryfunctor &functor) {
return PythonLightField(_lightField.Map(functor));
}
Expand Down
25 changes: 16 additions & 9 deletions python/src/PythonGreyscale.cc → python/src/PythonUnary.cc
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
#include "PythonUnary.h"
#include "npp.h"
#include "Format.h"
#include <boost/python/numpy.hpp>
#include <iostream>
#include <vector>
#include "PythonGreyscale.h"
#include "npp.h"
#include "ipp.h"
#include "Format.h"

namespace np = boost::python::numpy;

namespace lightdb::python {
shared_reference <LightField> PythonGreyscale::CPU::operator()(LightField &input) {
shared_reference <LightField> PythonUnary::CPU::operator()(LightField &input) {
np::initialize();
const auto channels = 3u;
auto &data = dynamic_cast<lightdb::physical::CPUDecodedFrameData&>(input);
lightdb::physical::CPUDecodedFrameData output(data.configuration(), data.geometry());

for(auto& frame: data.frames()) {

//ToDo: add equality operator
// frame->format() == lightdb::video::Format::nv12()
Allocate(frame->height(), frame->width(), channels);
IppiSize size{static_cast<int>(frame->width()), static_cast<int>(frame->height())};
auto y_in = reinterpret_cast<const unsigned char*>(frame->data().data());
auto uv_in = y_in + frameSize_;
output.frames().emplace_back(LocalFrameReference::make<LocalFrame>(*frame, frame->data().size(), lightdb::video::Format::nv12()));
output.frames().emplace_back(LocalFrameReference::make<LocalFrame>(*frame, frame->data().size(), frame->format()));
auto y_out = output.frames().back()->data().data();
auto uv_out = y_out + frameSize_;

// NV12 -> RGB
CHECK_EQ(ippiYCbCr420ToRGB_8u_P2C3R((Ipp8u*)y_in, frame->width(), (Ipp8u*)uv_in, frame->width(), rgb_.data(), channels * frame->width(), size), ippStsNoErr);

nv12ToRgb(frame, y_in, uv_in, channels, size);
// RGB --> Numpy
np::dtype dtype = np::dtype::get_builtin<unsigned char>();
np::ndarray py_array = np::from_data(
Expand All @@ -40,8 +41,14 @@ namespace lightdb::python {
boost::python::call<void>(callable_, swap);

// RGB -> NV12
CHECK_EQ(ippiRGBToYCbCr420_8u_C3P2R(rgb_.data(), channels * frame->width(), (Ipp8u*)y_out, frame->width(), (Ipp8u*)uv_out, frame->width(), size), ippStsNoErr);
CHECK_EQ(ippiRGBToYCbCr420_8u_C3P2R(rgb_.data(), channels * frame->width(), const_cast<Ipp8u*>(reinterpret_cast<const Ipp8u*>(y_out)), frame->width(),
const_cast<Ipp8u*>(reinterpret_cast<const Ipp8u*>(uv_out)), frame->width(), size), ippStsNoErr);
}
return output;
}

void PythonUnary::CPU::nv12ToRgb(auto& frame, auto y_in, auto uv_in, const auto channels, const IppiSize& size) {
CHECK_EQ(ippiYCbCr420ToRGB_8u_P2C3R(const_cast<Ipp8u*>(reinterpret_cast<const Ipp8u*>(y_in)), frame->width(), const_cast<Ipp8u*>(reinterpret_cast<const Ipp8u*>(uv_in)),
frame->width(), rgb_.data(), channels * frame->width(), size), ippStsNoErr);
}
}