Speed of Matrix-Multiplication (in Matlab, C, other PCs)
31 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I'm working on an object detection algorithm ( HOG ). Their (paper-guys) tool is written in C and needs "less than a second [for] 4000 detection windows".
I use Matlab. After optimizing my code for speed, the biggest 'time sink' (80% cpu time) is a matrix-multiplication (it is the linear kernel of a SVM classification). I striped it down to:
nF = 3780; % number of features
nV = 3120; % number of support vectors
V = rand(nV,nF); % support vectors
N = 5000;
S = rand(N,nF);
tic
K = V * S'; % Elapsed time is ~2 seconds.
toc
The matrix-multiplication takes 2sec (where the paperguys do it in 1sec). I tried mex'ing it, but that takes 35% longer. I tried parallel computing with splitting S, but also took much longer.
Now my questions are about explanation and understanding this: How much faster is a matrix multiplication like this in C? How much influence has the PC spec? I guess it is impossible to speedup a matrix multiplication in Matlab?
0 Commenti
Risposta accettata
James Tursa
il 21 Ago 2015
Modificato: James Tursa
il 21 Ago 2015
MATLAB uses a very fast and highly optimized BLAS library to do matrix multiplication. You are unlikely to find anything faster than simply doing V * S' as you currently are because this calls the BLAS library routine in the background (the parser will pass the transpose info to the BLAS routine without actually forming S' explicitly first). And part of the optimization is multi-threading, so you are already getting that benefit simply by using the * operator. The fastest way to do matrix multiplication in C for the sizes you are using is to call this BLAS library (same thing MATLAB is already doing).
What do you mean "the paperguys do it in 1sec"? You have a program that is doing the same size matrix multiply in 1 sec on the exact same computer? Are you sure they are doing the same matrix multiply? What computer are you using? Don't use the first MATLAB timing you do because that time includes the time to load the function. Do a couple more tests and then see what you get for timing.
6 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Parallel Computing Fundamentals in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!