1

I have code that calls ismember(A,B) some 2^20 times on various gpuArrays A and B, where A is a non-sparse matrix with several million integer entries with sorted rows and B is a non-sparse sorted vector of a few thousand distinct integer entries. If it helps, with linear indexing A(:) can be had in sorted form.

For sorted (integer) non-gpu arrays, the fastest option is builtin('_ismemberhelper',a,b), ismembc is slower, both of which are much faster than ismember (since they omit all the checks), cannot operate with gpuArrays and are still slower than ismember on gpuArrays. That is, in terms of speed:

ismember on GPU > builtin('_ismemberhelper',a,b) > ismembc() > ismember on CPU

Now, I have looked in the main ismember.m file to see what code it uses, but all I have been able to find that relates is this:

    else %(a,b, are some other class like gpuArray, syb object)
    lia = false(size(a));
    if nargout <= 1
        for i=1:numelA
            lia(i) = any(a(i)==b(:));   % ANY returns logical.
        end
    else
        for i=1:numelA
            found = a(i)==b(:); % FIND returns indices for LOCB.
            if any(found)
                lia(i) = true;
                found = find(found);
                locb(i) = found(1);
            end
        end
    end
end

(Other seemingly relevant parts of the code used functions like unique and sortrows, which do not support gpuArrays.) It sure not only does not look right for gpu accelerated code, but it also, as expected, does not even come close to the performance of ismember for gpuArrays. Thus:

(Question 1) Is the routine for the GPU-accelerated version of ismember openly accessible (like ismember.m is)?

(Question 2) More importantly, is there a function/algorithm that would be faster than the GPU-accelerated ismember for my specific case (sorted integer-valued arrays of the aforementioned sizes).

I am currently using MATLAB 2014b and GTX 460 with 1 GB of VRAM.

M.G.
  • 293
  • 1
  • 13
  • I think Question 2 can be answered by this thread http://stackoverflow.com/questions/29101796/find-elements-meeting-any-of-a-number-of-criteria – GameOfThrows May 27 '15 at 11:16
  • For question 1, type at command window `edit gpuArray/ismember` –  May 27 '15 at 11:37
  • @CST-Link: it only gives (commented out) description of usage of the function and an example, then refers to `ISMEMBER` docu. @GameOfThrows: It does not look like it does. – M.G. May 27 '15 at 11:40
  • @July Then, most likely, the .m file is just for class interface, and the actual implementation is in a .mex file. Look into the MATLAB installation folder (e.g. `C:\Program Files\MATLAB`) under the `toolboxes\` folder and look there or in subfolders for the `gpuArray`. Maybe you can find hints. –  May 27 '15 at 11:47
  • Have you tried a hashtable? (`containers.Map`)? – knedlsepp May 27 '15 at 12:14
  • I am not familiar with `containers.Map`. Could you please elaborate a little bit on how it would work in my case? FYI, the integers in the arrays `A` and `B` are actually hashes of n-tuples. – M.G. May 27 '15 at 12:18
  • You will have to convert your values to char-arrays and then use them like so: `database = containers.Map({'asdf','qwer'},true(1,2));` `database.isKey('asdf')` – knedlsepp May 27 '15 at 15:39
  • @knedlsepp: That much I got from the docu :-) But how do I do it automatically for millions of entries? – M.G. May 27 '15 at 15:44
  • Look at [this](http://stackoverflow.com/questions/20166847/faster-version-of-find-for-sorted-vectors-matlab) question. – Autonomous May 27 '15 at 16:52
  • @ParagS.Chandakkar: thanks for link, I have already seen it, but I don't see immediately how it applies to my case as the output needs to be an index vector, not just first index, and, more importantly, the second input (the source of values to be searched for) is an array, not just lower and upper bound. I'd appreciate a full answer. – M.G. May 27 '15 at 17:24

0 Answers0