Giter Club home page Giter Club logo

pq-with-blas's Introduction

Introduction

This project compares the run-time speed of the look-up table pre-computation procedure in Product Quantization and its several variants. Intel's MKL library (BLAS & SparseBLAS) is used for acceleration; a built-in implementation of matrix multipliation is also included for comparison.

We compare the following PQ-like methods:

  • PQ (Product Quantization).
  • OPQ (Optimized Product Quantization).
  • CQ (Composite Quantization).
  • SCQ (Sparse Composite Quantization).
  • TQ (Tree Quantization).

Another two PQ-like methods, CKM (Cartesian K-means) and AQ (Additive Quantization), are not included, since their pre-computation procedure is the same as OPQ and CQ, respectively.

MKL library provides acceleration for matrix multiplication operations (both dense and sparse matrices). PQ, OPQ, and CQ can be accelerated by MKL's BLAS routine, and SCQ can be sped-up be MKL's SparseBLAS routine. TQ is a little bit special. Due to its structured sparsity, MKL's BLAS routine can still be adopted for better speed-up (compared against SparseBLAS).

Experiments

Settings

We report the pre-computation time (in millisecond) of each query (average over 10k queries). Two input settings are evaluated, "single query" and "multiple queries" (50 queries in a batch). The time consumption is measured on a workstation, equiped with Intel Xeon E5-2640 CPU @ 2.50GHz (single-threaded).

Results

Method Time Complexity 128 x 1 128 x 50 960 x 1 960 x 50
PQ D * K 0.024 / 0.015 0.025 / 0.004 0.247 / 0.048 0.232 / 0.018
OPQ D * D + D * K 0.044 / 0.017 0.040 / 0.005 1.177 / 0.178 1.190 / 0.075
CQ D * M * K 0.271 / 0.050 0.252 / 0.018 2.004 / 0.306 1.992 / 0.130
SCQ D * K 0.050 / 0.053 0.048 / 0.014 0.272 / 0.171 0.270 / 0.112
TQ 2 * D * K 0.058 / 0.020 0.056 / 0.006 0.489 / 0.094 0.488 / 0.037

Note: for query size X x Y, X is the number of feature dimensions, and Y is the number of queries in each input batch. The first time is for the built-in implementation, and the second time is for the MKL-based implementation. We choose SCQ's sparsity so that its complexity is the same as that of PQ.

Analysis

  • MKL's BLAS routine is much more powerful than the built-in implementation, and its advantage grows as the input batch size increases.
  • MKL's SparseBLAS routine is also slightly better than the built-in version, but less efficient than the BLAS routine (comparing PQ and SCQ).
  • TQ is more efficient than SCQ due to its structured sparsity.

pq-with-blas's People

Contributors

jiaxiang-wu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pq-with-blas's Issues

Where is the implementation of quantization algorithm?

Thanks for your great work! But I only found the code of comparing and parameter setting parts, but not algorithm implementation for these quantization methods.
Do I miss something? Or this project doesn't include the algorithm part?
Thanks again.

compile file on CentOS 7.0.1406

It is ok on Ubuntu 14.04.4 LTS, but fail on CentOS 7.
This is the compile error:

g++ -MM -Wall -O2 -I/opt/intel/mkl/include Main.cc > Main.d.$$; \
sed 's,\(Main.\)\.o[ :]*,\1.o Main.d ,g' < Main.d.$$ > Main.d; \
rm -f Main.d.$$
g++ -MM -Wall -O2 -I/opt/intel/mkl/include ProdQuan.cc > ProdQuan.d.$$; \
sed 's,\(ProdQuan.\)\.o[ :]*,\1.o ProdQuan.d ,g' < ProdQuan.d.$$ > ProdQuan.d; \
rm -f ProdQuan.d.$$
g++ -MM -Wall -O2 -I/opt/intel/mkl/include BaseQuan.cc > BaseQuan.d.$$; \
sed 's,\(BaseQuan.\)\.o[ :]*,\1.o BaseQuan.d ,g' < BaseQuan.d.$$ > BaseQuan.d; \
rm -f BaseQuan.d.$$
g++ -MM -Wall -O2 -I/opt/intel/mkl/include OptProdQuan.cc > OptProdQuan.d.$$; \
sed 's,\(OptProdQuan.\)\.o[ :]*,\1.o OptProdQuan.d ,g' < OptProdQuan.d.$$ > OptProdQuan.d; \
rm -f OptProdQuan.d.$$
g++ -MM -Wall -O2 -I/opt/intel/mkl/include CompQuan.cc > CompQuan.d.$$; \
sed 's,\(CompQuan.\)\.o[ :]*,\1.o CompQuan.d ,g' < CompQuan.d.$$ > CompQuan.d; \
rm -f CompQuan.d.$$
g++ -MM -Wall -O2 -I/opt/intel/mkl/include TreeQuan.cc > TreeQuan.d.$$; \
sed 's,\(TreeQuan.\)\.o[ :]*,\1.o TreeQuan.d ,g' < TreeQuan.d.$$ > TreeQuan.d; \
rm -f TreeQuan.d.$$
g++ -MM -Wall -O2 -I/opt/intel/mkl/include BlasWrapper.cc > BlasWrapper.d.$$; \
sed 's,\(BlasWrapper.\)\.o[ :]*,\1.o BlasWrapper.d ,g' < BlasWrapper.d.$$ > BlasWrapper.d; \
rm -f BlasWrapper.d.$$
g++ -MM -Wall -O2 -I/opt/intel/mkl/include SprsCompQuan.cc > SprsCompQuan.d.$$; \
sed 's,\(SprsCompQuan.\)\.o[ :]*,\1.o SprsCompQuan.d ,g' < SprsCompQuan.d.$$ > SprsCompQuan.d; \
rm -f SprsCompQuan.d.$$
g++    -c -o SprsCompQuan.o SprsCompQuan.cc
In file included from BaseQuan.h:14:0,
                 from SprsCompQuan.h:11,
                 from SprsCompQuan.cc:8:
SprsArray.hpp:11:17: 致命错误:mkl.h:没有那个文件或目录
 #include <mkl.h>
                 ^
编译中断。
make: *** [SprsCompQuan.o] 错误 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.