Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pranay Code Review #30

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 32 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()
1 change: 1 addition & 0 deletions plugins/yolo/darknet
Submodule darknet added at c72527
10 changes: 9 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ find_package(Python2 COMPONENTS Development)
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)
mundrapranay marked this conversation as resolved.
Show resolved Hide resolved
#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")
include_directories(${LIGHTDB_PYTHON_INCLUDE_DIRS})
Expand All @@ -27,6 +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 opencv_core)
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
50 changes: 50 additions & 0 deletions python/include/PythonUnary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef LIGHTDB_PYTHON_UNARY_H
#define LIGHTDB_PYTHON_UNARY_H


#include "ipp.h"
mundrapranay marked this conversation as resolved.
Show resolved Hide resolved
#include "Functor.h"
#include <Python.h>


namespace lightdb::python {
class PythonUnary : public lightdb::functor::unaryfunctor {
class CPU : public lightdb::functor::unaryfunction {
public:
explicit CPU(PyObject* const callable, const bool deterministic=true)
: lightdb::functor::unaryfunction(lightdb::physical::DeviceType::CPU,
lightdb::Codec::raw(),
deterministic),
callable_(callable)
{
CHECK_NOTNULL(callable);
callable->ob_refcnt++;
mundrapranay marked this conversation as resolved.
Show resolved Hide resolved
// 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_);
}
}

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 rgbSize_;
unsigned int frameSize_;
std::vector<unsigned char> rgb_;
};

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

}

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


Expand All @@ -26,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 @@ -80,8 +80,8 @@ 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_<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);
};
} // namespace Python
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
54 changes: 54 additions & 0 deletions python/src/PythonUnary.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "PythonUnary.h"
#include "npp.h"
mundrapranay marked this conversation as resolved.
Show resolved Hide resolved
#include "Format.h"
#include <boost/python/numpy.hpp>
#include <iostream>
#include <vector>

namespace np = boost::python::numpy;

namespace lightdb::python {
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(), frame->format()));
auto y_out = output.frames().back()->data().data();
auto uv_out = y_out + frameSize_;

// NV12 -> RGB
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(
rgb_.data(),
dtype,
boost::python::make_tuple(channels, frame->width(), frame->height()),
boost::python::make_tuple(1 , sizeof(unsigned char) * channels, sizeof(unsigned char) * channels * frame->width()),
boost::python::object());

np::ndarray swap = py_array.transpose();
boost::python::call<void>(callable_, swap);

// RGB -> NV12
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);
}
}
16 changes: 12 additions & 4 deletions python/test/test.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import pytest
import pylightdb as db
import pylightdb
from pylightdb import *

def scan_test():
PythonLightField pydb = db.Scan()
x = SpatiotemporalRange(0,0)
y = SpatiotemporalRange(0,0)
z = SpatiotemporalRange(0,0)
vol = Volume(x,y,z)
geo = EquirectangularGeometry(2,1)
env = LocalEnvironment()
optimizer = HeuristicOptimizer(env)
coordinator = Coordinator()
query = Load("/home/pranay99/lightdb/test/resources/test-pattern.h264", {"Volume":vol, "Projection":geo}).Save("/home/pranay99/test.mp4")
coordinator.Execute(query.query(), optimizer)
22 changes: 22 additions & 0 deletions python/test/testGrey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pylightdb
import numpy as np
import cv2 as cv
from PIL import Image
from pylightdb import *

x = SpatiotemporalRange(0,0)
y = SpatiotemporalRange(0,0)
z = SpatiotemporalRange(0,0)
vol = Volume(x,y,z)
geo = EquirectangularGeometry(0,0)
env = LocalEnvironment()
optimizer = HeuristicOptimizer(env)
coordinator = Coordinator()
def rgb2gray(rgb):
rgb_weights = [0.2989, 0.5870, 0.1140]
grayscale_image = np.dot(rgb[...,:3], rgb_weights)
rgb[:,:,:] = grayscale_image[:,:,np.newaxis]
return rgb
grey = PythonGreyscale(rgb2gray)
query = Load("/home/pranay99/colorsrc.h264", {"Volume":vol, "Projection":geo}).Map(grey).Save("/home/pranay99/lambdaTest.h264")
coordinator.Execute(query.query(), optimizer)
13 changes: 0 additions & 13 deletions pythonTests/test.py

This file was deleted.

4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ get_property(LIGHTDB_INCLUDES DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INC
string(REPLACE ";" "|" LIGHTDB_INCLUDES_STRING "${LIGHTDB_INCLUDES}")

foreach(LIGHTDB_PLUGIN_DIR ${LIGHTDB_PLUGIN_DIRS})
message("Lightdb plugin dir: ${LIGHTDB_PLUGIN_DIR}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

message("CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}")
message("LIGHTDB_PLUGIN_DIR: ${LIGHTDB_PLUGIN_DIR}")
message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
if (IS_DIRECTORY ${LIGHTDB_PLUGIN_DIR})
get_filename_component(LIGHTDB_PLUGIN_NAME ${LIGHTDB_PLUGIN_DIR} NAME_WE)
string(TOLOWER "${LIGHTDB_PLUGIN_DIR}/cmake-build-${CMAKE_BUILD_TYPE}" LIGHTDB_PLUGIN_BINARY_DIR)
Expand Down
24 changes: 24 additions & 0 deletions test/src/execution/SelectionTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ TEST_F(SelectionTestFixture, testSelectPhi) {
EXPECT_EQ(remove(Resources.out.hevc), 0);
}

TEST_F(SelectionTestFixture, testSelectPhi2) {
auto query = Load("/home/maureen/lightdb/cmake-build-debug-remote/test/resources/red10/stream0.h264")
.Select(PhiRange{0, rational_times_real({1, 4}, PI)})
.Encode()
.Save("/home/maureen/encoded0.hevc");

Coordinator().execute(query);

EXPECT_VIDEO_VALID(Resources.out.hevc);
EXPECT_VIDEO_FRAMES(Resources.out.hevc, Resources.red10.frames);
EXPECT_VIDEO_RESOLUTION(Resources.out.hevc, Resources.red10.height / 4, Resources.red10.width);
EXPECT_VIDEO_RED(Resources.out.hevc);
EXPECT_EQ(remove(Resources.out.hevc), 0);
}

TEST_F(SelectionTestFixture, testSelectTheta) {
REQUIRE_GPU();

Expand Down Expand Up @@ -156,6 +171,15 @@ TEST_F(SelectionTestFixture, testTemporalThetaSelect) {
EXPECT_EQ(remove(Resources.out.hevc), 0);
}

TEST_F(SelectionTestFixture, testPythonQuery) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

auto query = Load("/home/maureen/lightdb/test/resources/tiles/tile-6.hevc")
.Select(PhiRange{0, rational_times_real({3, 4}, PI)})
.Encode()
.Save("/home/maureen/selected-tile-6-test.hevc");

Coordinator().execute(query);
}

TEST_F(SelectionTestFixture, testDegenerateTimeSelect) {
REQUIRE_GPU();

Expand Down
2 changes: 1 addition & 1 deletion test/src/execution/UDFTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TEST_F(UDFTestFixture, testGreyscale) {
auto query = Scan(Resources.red10.name)
.Map(lightdb::Greyscale)
.Encode()
.Save(Resources.out.hevc);
.Save("/home/maureen/grey_test.hevc");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?


Coordinator().execute(query);

Expand Down