-
Notifications
You must be signed in to change notification settings - Fork 6
Pranay Code Review #30
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
base: master
Are you sure you want to change the base?
Changes from 32 commits
0e68809
219ebef
c57f8b6
6fd1b89
f4f3682
988772c
434bcc5
c53e035
2dede26
242a3f5
829f038
8609a99
18f2a4c
541ba35
d81b2d8
c7a0260
d0c46aa
ab30969
7bcb70b
f76f67b
a46ab1e
8d7db64
693a786
e8bd9c5
5ebe19d
ccf86c9
c0426df
244ed09
2c04eff
207128c
883bf72
6702dcd
3a70b76
0dcec19
fe9f502
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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() |
| 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.
Outdated
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.
Outdated
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 | ||
| 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.
Outdated
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); | ||
| } | ||
| } | ||
| 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) |
| 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) |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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}") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); | ||
|
|
||
|
|
@@ -156,6 +171,15 @@ TEST_F(SelectionTestFixture, testTemporalThetaSelect) { | |
| EXPECT_EQ(remove(Resources.out.hevc), 0); | ||
| } | ||
|
|
||
| TEST_F(SelectionTestFixture, testPythonQuery) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
|
|
||
| Coordinator().execute(query); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.