Skip to content

Commit

Permalink
Adding FLINNG Library (IntelLabs#47)
Browse files Browse the repository at this point in the history
* Adding FLINNG Library

* Add the default  value of parameters of the Flinng descriptor Set

* Update both dockerfiles to match (other than coverage)

* remove parma value from Flinngvoid FlinngDescriptorSet::getFlinngParams
  • Loading branch information
s-gobriel authored May 26, 2022
1 parent dcd4aaf commit 895b1c3
Show file tree
Hide file tree
Showing 23 changed files with 1,160 additions and 19 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ else()
add_subdirectory(distributed)

link_directories(/usr/local/lib /usr/lib/x86_64-linux-gnu/)
include_directories(/usr/include/jsoncpp utils/include/ src/pmgd/include src/pmgd/util include/ src/vcl ${CMAKE_CURRENT_BINARY_DIR}/utils/src/protobuf)
include_directories(/usr/include/jsoncpp utils/include/ src/pmgd/include src/pmgd/util include/ src/vcl /usr/include ${CMAKE_CURRENT_BINARY_DIR}/utils/src/protobuf)
add_library(dms SHARED src/BoundingBoxCommand.cc src/CommunicationManager.cc src/DescriptorsCommand.cc src/DescriptorsManager.cc src/ExceptionsCommand.cc src/ImageCommand.cc src/PMGDIterators.cc src/PMGDQuery.cc src/PMGDQueryHandler.cc src/QueryHandler.cc src/QueryMessage.cc src/RSCommand.cc src/SearchExpression.cc src/Server.cc src/VDMSConfig.cc src/VideoCommand.cc src/AutoDeleteNode.cc ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(dms vcl pmgd pmgd-util protobuf vdms-utils pthread)


add_executable(vdms src/vdms.cc)
target_link_libraries(vdms dms vdms_protobuf vcl tiledb faiss jsoncpp ${OpenCV_LIBS})
endif ()
target_link_libraries(vdms dms vdms_protobuf vcl tiledb faiss flinng jsoncpp ${OpenCV_LIBS})
endif ()
4 changes: 3 additions & 1 deletion docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ RUN git clone --branch v1.40.0 https://github.com/grpc/grpc.git && \
git clone --branch v0.6 https://github.com/tristanpenman/valijson.git && \
git clone --branch v3.21.2 https://github.com/Kitware/CMake.git && \
git clone --branch v1.7.1 https://github.com/facebookresearch/faiss.git && \
git clone https://github.com/tonyzhang617/FLINNG.git && \
curl http://zlib.net/zlib-1.2.12.tar.gz -o zlib-1.2.12.tar.gz && \
curl https://downloads.apache.org/commons/codec/binaries/commons-codec-1.15-bin.tar.gz -o /commons-codec-1.15-bin.tar.gz && \
curl https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/json-simple/json-simple-1.1.1.jar -o /usr/share/java/json-simple-1.1.1.jar && \
Expand All @@ -45,6 +46,7 @@ RUN git clone --branch v1.40.0 https://github.com/grpc/grpc.git && \
RUN cd /CMake && ./bootstrap && make ${BUILD_THREADS} && make install && \
cd /swig && ./autogen.sh && ./configure && make ${BUILD_THREADS} && make install && \
cd /faiss && mkdir build && cd build && cmake -DFAISS_ENABLE_GPU=OFF .. && make ${BUILD_THREADS} && make install && \
cd /FLINNG && mkdir build && cd build && cmake .. && make ${BUILD_THREADS} && make install && \
cd /grpc && git submodule update --init --recursive && cd third_party/protobuf/cmake && mkdir build && cd build && cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE .. && make ${BUILD_THREADS} && make install && \
cd ../../../abseil-cpp && mkdir build && cd build && cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE .. && make ${BUILD_THREADS} && make install && \
cd ../../re2/ && mkdir build && cd build && cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE .. && make ${BUILD_THREADS} && make install && \
Expand All @@ -66,7 +68,7 @@ RUN cd / && tar xf 1.3.1.tar.gz && rm 1.3.1.tar.gz && \
cd TileDB-1.3.1 && mkdir build && cd build && \
../bootstrap --prefix=/usr/local/ && make $BUILD_THREADS && make install-tiledb && \
rm -rf /TileDB-1.3.1

RUN ln -s /grpc/third_party/protobuf/cmake/build/protoc /grpc/third_party/protobuf/src/protoc && \
cd /grpc/third_party/protobuf/java/core && mvn package && \
cp $(ls target/protobuf-java*.jar) /usr/share/java/protobuf.jar
Expand Down
4 changes: 3 additions & 1 deletion docker/check-in/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Copyright (C) 2021 Intel Corporation
#Copyright (C) 2021 Intel Corporation
#SPDX-License-Identifier: MIT

ARG UBUNTU_VERSION=20.04
Expand Down Expand Up @@ -37,6 +37,7 @@ RUN git clone --branch v1.40.0 https://github.com/grpc/grpc.git && \
git clone --branch v0.6 https://github.com/tristanpenman/valijson.git && \
git clone --branch v3.21.2 https://github.com/Kitware/CMake.git && \
git clone --branch v1.7.1 https://github.com/facebookresearch/faiss.git && \
git clone https://github.com/tonyzhang617/FLINNG.git && \
curl http://zlib.net/zlib-1.2.12.tar.gz -o zlib-1.2.12.tar.gz && \
curl https://downloads.apache.org/commons/codec/binaries/commons-codec-1.15-bin.tar.gz -o /commons-codec-1.15-bin.tar.gz && \
curl https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/json-simple/json-simple-1.1.1.jar -o /usr/share/java/json-simple-1.1.1.jar && \
Expand All @@ -45,6 +46,7 @@ RUN git clone --branch v1.40.0 https://github.com/grpc/grpc.git && \
RUN cd /CMake && ./bootstrap && make ${BUILD_THREADS} && make install && \
cd /swig && ./autogen.sh && ./configure && make ${BUILD_THREADS} && make install && \
cd /faiss && mkdir build && cd build && cmake -DFAISS_ENABLE_GPU=OFF .. && make ${BUILD_THREADS} && make install && \
cd /FLINNG && mkdir build && cd build && cmake .. && make ${BUILD_THREADS} && make install && \
cd /grpc && git submodule update --init --recursive && cd third_party/protobuf/cmake && mkdir build && cd build && cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE .. && make ${BUILD_THREADS} && make install && \
cd ../../../abseil-cpp && mkdir build && cd build && cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE .. && make ${BUILD_THREADS} && make install && \
cd ../../re2/ && mkdir build && cd build && cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE .. && make ${BUILD_THREADS} && make install && \
Expand Down
18 changes: 15 additions & 3 deletions include/vcl/DescriptorSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
#include <string>
#include <vector>
#include <map>

#include "DescriptorParams.h"
#include "Exception.h"

namespace VCL {

enum DescriptorSetEngine {FaissFlat, FaissIVFFlat,
TileDBDense, TileDBSparse};
TileDBDense, TileDBSparse,
Flinng};

enum DistanceMetric {L2, IP};

Expand All @@ -58,6 +59,7 @@ namespace VCL {
typedef float* DescDataArray;

class DescriptorSetData;
class DescriptorParams;

private:

Expand Down Expand Up @@ -85,7 +87,8 @@ namespace VCL {
*/
DescriptorSet(const std::string &set_path, unsigned dim,
DescriptorSetEngine eng = FaissFlat,
DistanceMetric metric = L2);
DistanceMetric metric = L2,
VCL::DescriptorParams *param = NULL);

~DescriptorSet();

Expand Down Expand Up @@ -122,6 +125,8 @@ namespace VCL {
*/
unsigned get_dimensions();

void finalize_index();

/**
* Returns the number of descriptors in the set
*/
Expand All @@ -144,6 +149,8 @@ namespace VCL {
*/
long add(DescDataArray descriptors, unsigned n, long* labels = NULL);

long add_and_store(DescDataArray descriptors, unsigned n, long* labels = NULL);

/**
* Search for the k closest neighborhs
*
Expand All @@ -157,6 +164,8 @@ namespace VCL {
void search(DescDataArray queries, unsigned n, unsigned k,
long* ids, float* distances);

void search(DescDataArray queries, unsigned n, unsigned k,
long* ids);
/**
* Search for neighborhs within a radius.
*
Expand Down Expand Up @@ -235,6 +244,7 @@ namespace VCL {
*/
long add(DescDataArray descriptors, unsigned n, LabelIdVector& labels);

long add_and_store(DescDataArray descriptors, unsigned n, LabelIdVector& labels);
/**
* Search for the k closest neighborhs
* // Add comment on why we use k and n_queries.
Expand All @@ -249,6 +259,8 @@ namespace VCL {
void search(DescDataArray query, unsigned n, unsigned k,
DescIdVector& ids, DistanceVector& distances);

void search(DescDataArray query, unsigned n, unsigned k,
DescIdVector& ids);
/**
* Find the label of the feature vector, based on the closest
* neighbors.
Expand Down
2 changes: 2 additions & 0 deletions src/DescriptorsCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ Json::Value AddDescriptorSet::construct_responses(
eng = VCL::TileDBDense;
else if (eng_str == "TileDBSparse")
eng = VCL::TileDBSparse;
else if (eng_str == "Flinng")
eng = VCL::Flinng;
else
throw ExceptionCommand(DescriptorSetError, "Engine not supported");

Expand Down
2 changes: 1 addition & 1 deletion src/ImageCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ int AddImage::construct_protobuf(PMGDQuery& query,
// Add Image node
query.AddNode(node_ref, VDMS_IM_TAG, props, Json::Value());

img.store(file_name, vcl_format);
img.store(file_name, vcl_format);

// In case we need to cleanup the query
error["image_added"] = file_name;
Expand Down
1 change: 0 additions & 1 deletion src/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ Server::Server(std::string config_file)
->get_string_value("backup_path", DEFAULT_BACKUP_PATH);
_db_path = VDMSConfig::instance()
->get_string_value("db_root_path", DEFAULT_DB_ROOT);


PMGDQueryHandler::init();
QueryHandler::init();
Expand Down
4 changes: 2 additions & 2 deletions src/vcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ find_package( OpenCV REQUIRED )

include_directories(../../include . /usr/local/include/opencv4 /usr/include/jsoncpp)

add_library(vcl SHARED DescriptorSet.cc DescriptorSetData.cc Exception.cc FaissDescriptorSet.cc Image.cc KeyFrame.cc TDBDenseDescriptorSet.cc TDBDescriptorSet.cc TDBImage.cc TDBObject.cc TDBSparseDescriptorSet.cc utils.cc Video.cc CustomVCL.cc)
target_link_libraries(vcl lapack faiss avformat avcodec swscale ${OpenCV_LIBS})
add_library(vcl SHARED DescriptorSet.cc DescriptorSetData.cc Exception.cc FaissDescriptorSet.cc FlinngDescriptorSet.cc Image.cc KeyFrame.cc TDBDenseDescriptorSet.cc TDBDescriptorSet.cc TDBImage.cc TDBObject.cc TDBSparseDescriptorSet.cc utils.cc Video.cc CustomVCL.cc)
target_link_libraries(vcl lapack faiss flinng avformat avcodec swscale ${OpenCV_LIBS})
45 changes: 45 additions & 0 deletions src/vcl/DescriptorParams.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2017 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @section DESCRIPTION
*
*/
using namespace VCL;

DescriptorParams::DescriptorParams(uint64_t numrows = 3, uint64_t cellsperrow = (1<<12),
uint64_t numhashtables = (1<<9), uint64_t hashespertable = 14,
uint64_t subhashbits = 2, uint64_t cutoff=6) {
this->num_rows = numrows;
this->cells_per_row= cellsperrow;
this->num_hash_tables = numhashtables;
this->hashes_per_table = hashespertable;
this->sub_hash_bits = subhashbits; //sub_hash_bits * hashes_per_table must be less than 32, otherwise segfault will happen
this->cut_off= cutoff;
}


76 changes: 76 additions & 0 deletions src/vcl/DescriptorParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2017 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @section DESCRIPTION
*
* This file declares the C++ Interface for the abstract DescriptorSetData object.
*/

#pragma once

#include <string>
#include <vector>
#include <fstream>
#include <mutex>
#include <map>

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>

#include "vcl/DescriptorSet.h"

namespace VCL {

class DescriptorParams {

public:
/* Params needed for FLINNG */
//constants for now until we derive them from N and dimensions
uint64_t num_rows;
uint64_t cells_per_row;
uint64_t num_hash_tables;
uint64_t hashes_per_table;
uint64_t sub_hash_bits; //sub_hash_bits * hashes_per_table must be less than 32, otherwise segfault will happen
uint64_t cut_off;

DescriptorParams(uint64_t numrows = 3, uint64_t cellsperrow = (1<<12),
uint64_t numhashtables = (1<<9), uint64_t hashespertable = 14,
uint64_t subhashbits = 2, uint64_t cutoff=6) {
this->num_rows = numrows;
this->cells_per_row= cellsperrow;
this->num_hash_tables = numhashtables;
this->hashes_per_table = hashespertable;
this->sub_hash_bits = subhashbits;
this->cut_off= cutoff;
}

~DescriptorParams();
};
};
Loading

0 comments on commit 895b1c3

Please sign in to comment.