Hi Dmitriy,

 > Karl, can we verify assumptions about the format:
>
> (1) the compressed_marix.set method expects host memory pointers.

yes

> (2) the format is compressed row storage (CSR). Documentation never says
> explicitly that, and actually seems to have errors in size of elements
> and jumper arrays (it says jumper array has to be cols+1 long wheres in
> CSR it shoud actually be rows + 1 long, right? )

yes

> (3) the element sizes of jumper and column indices arrays are 32 bit and
> are in little endian order (at least for the open MP backend).

elements are in whatever order your machine supports.

Best regards,
Karli


> Right now I can't even get open mp sparse multiplication work although
> CSR format is not rocket science at all. Don't see a problem anywhere.
> Tried to read Vienna's code to converm the assumptions above, but this
> seems to be pretty elusive for the time being.
>
>
> On Fri, Jul 22, 2016 at 10:26 AM, Andrew Palumbo <[email protected]
> <mailto:[email protected]>> wrote:
>
>     Yep thats it.  Oh wow- well thats just embarrassing 😊.
>
>
>     Thanks very much for your time, Karl- much appreciated.
>
>
>     Andy
>
>     ------------------------------------------------------------------------
>     *From:* Karl Rupp <[email protected] <mailto:[email protected]>>
>     *Sent:* Friday, July 22, 2016 12:39:20 PM
>     *To:* Andrew Palumbo; viennacl-devel
>     *Subject:* Re: [ViennaCL-devel] Copying Values out of a
>     compressed_matrix
>     Hi,
>
>     your second and third arguments to memory_read() are incorrect:
>     The second argument is the offset from the beginning, the third
>     argument
>     is the number of bytes to be read. Shifting the zero to the second
>     position fixes the snippet (plus correcting the loop bounds when
>     printing at the end) :-)
>
>     Best regards,
>     Karli
>
>
>
>     On 07/22/2016 08:51 AM, Andrew Palumbo wrote:
>     > a couple of small mistakes in the previous c++ file:
>     >
>     >
>     > The memory_read(..) call should be:
>     >
>     >
>     >    // read data back into our product buffers
>     >    viennacl::backend::memory_read(handle1, product_size_row * 4, 0,
>     > product_row_ptr, false);
>     >    viennacl::backend::memory_read(handle2, product_NNz * 4, 0,
>     > product_col_ptr, false);
>     >    viennacl::backend::memory_read(handle, product_NNz * 8, 0,
>     > product_values_ptr, false);
>     >
>     >
>     > (read product_NNz * x bytes instead of product_size_row * x)
>     >
>     >
>     > I've attached the corrected file.
>     >
>     >
>     > Thanks
>     >
>     >
>     > Andy
>     >
>     > ------------------------------------------------------------------------
>     > *From:* Andrew Palumbo <[email protected] <mailto:[email protected]>>
>     > *Sent:* Thursday, July 21, 2016 11:03:59 PM
>     > *To:* Karl Rupp; viennacl-devel
>     > *Subject:* Re: [ViennaCL-devel] Copying Values out of a 
> compressed_matrix
>     >
>     > Hello,
>     >
>     >
>     > I've mocked up a sample of the compressed_matrix multiplication that
>     > I've been working with javacpp on in C++.  I am seeing the same type of
>     > memory errors when I try to read the data out of product, and into the
>     > output buffers as I was with javacpp.  By printing the matrix to stdout
>     > as in the compressed_matrix example we can see that there are values
>     > there, and they seem reasonable,  but when i use
>     > backend::memory_read(...)  to retrive the buffers, I'm getting values
>     > consistent with a memory error, and similar to what i was seeing in the
>     > javacpp code.  Maybe I am not using the handles correctly?  Admittedly
>     > my C++ is more than rusty, but I believe I am referencing the buffers
>     > correctly in the output.
>     >
>     >
>     > Below is the output of the attached file: sparse.cpp
>     >
>     >
>     > Thanks very much,
>     >
>     >
>     > Andy
>     >
>     >
>     >
>     > ViennaCL: compressed_matrix of size (10, 10) with 24 nonzeros:
>     >    (1, 2)    0.329908
>     >    (1, 3)    0.0110522
>     >    (1, 4)    0.336839
>     >    (2, 5)    0.0150778
>     >    (2, 7)    0.0143518
>     >    (3, 3)    0.217256
>     >    (3, 6)    0.346854
>     >    (3, 9)    0.45353
>     >    (4, 3)    0.407954
>     >    (4, 6)    0.651308
>     >    (5, 2)    0.676061
>     >    (5, 3)    0.0226486
>     >    (5, 4)    0.690264
>     >    (6, 5)    0.0998838
>     >    (6, 7)    0.0950744
>     >    (7, 2)    0.346173
>     >    (7, 3)    0.0115971
>     >    (7, 4)    0.353446
>     >    (7, 9)    0.684458
>     >    (8, 5)    0.0448123
>     >    (8, 7)    0.0426546
>     >    (8, 9)    0.82782
>     >    (9, 5)    0.295356
>     >    (9, 7)    0.281134
>     >
>     > row jumpers: [
>     > -36207072,32642,-39708721,32642,6390336,0,2012467744 
> <tel:2012467744>,32767,2012467968
>     <tel:2012467968>,32767,4203729,]
>     > col ptrs: [
>     > 
> 0,0,-39655605,32642,-36207072,32642,6390336,0,10,0,-39672717,32642,2012466352,32767,-32892691,32642,1,0,6390336,0,2012466344,32767,60002304,2059362829,]
>     > elements: [
>     > 
> 0.289516,0.304161,0.795779,0.334456,0.935264,0.585813,0.871237,0.811508,0.828558,0.0271863,6.92683e-310,6.92683e-310,1.061e-313,1.061e-313,6.36599e-314,4.24399e-314,6.36599e-314,6.92683e-310,4.24399e-314,1.2732e-313,2.122e-313,6.95324e-310,0.406537,0.0495716,0.370862,]
>     >
>     >
>     > and similarly for multiplication of 2 1x1 matrices:
>     >
>     > Result:
>     >
>     > ViennaCL: compressed_matrix of size (1, 1) with 1 nonzeros:
>     >    (0, 0)    0.117699
>     >
>     > row jumpers: [
>     > -717571424,32767,]
>     > col ptrs: [
>     > 6386240,]
>     > elements: [
>     > 0.289516,6.9479e-310,]
>     >
>     >
>     >
>     >
>     > ------------------------------------------------------------------------
>     > *From:* Andrew Palumbo <[email protected] <mailto:[email protected]>>
>     > *Sent:* Wednesday, July 20, 2016 5:40:31 PM
>     > *To:* Karl Rupp; viennacl-devel
>     > *Subject:* Re: [ViennaCL-devel] Copying Values out of a 
> compressed_matrix
>     >
>     > Oops, sorry about not cc'ing all.
>     >
>     >
>     > I do not get correct data back for a (Random.nextDouble() populated) 1 x
>     > 1 Matrix.
>     >
>     >
>     > A:
>     >
>     >    Row Pointer: [0, 1 ]
>     >
>     >    Col Pointer: [0 ]
>     >    element Pointer: [0.6465821602909256 ]
>     >
>     >
>     > B:
>     >
>     >
>     >    Row Pointer: [0, 1 ]
>     >    Col Pointer: [0 ]
>     >    element Pointer: [0.9513577109193919 ]
>     >
>     >
>     > C = A %*% B
>     >
>     >    Row Pointer: [469762248, 32632]
>     >    Col Pointer: [469762248 ]
>     >    element Pointer: [6.9245198744523E-310 ]
>     >
>     >
>     > ouch.
>     >
>     >
>     > It looks like I'm not copying the Buffers correctly at all.  I'm may be
>     > using the javacpp buffers incorrectly here, or I have possibly wrapped
>     > the viennacl::backend::memory_handle class incorrectly, so I'm using a
>     > pointer to the wrong memory from eg. 
> viennacl::compressed_matrix::handle.
>     >
>     >
>     > I mentioned before that the multiplication completed in on small <~300 x
>     > 300 matrices because if I try to multiply two larger sparse matrices, an
>     > err the JVM crashes with a SIGSEGV.
>     >
>     >
>     > Since this code is all wrapped with javacpp, I don't really have a small
>     > sample that I can show you (not going to dump a whole bunch of code on
>     > you).
>     >
>     >
>     > I'll keep trying to figure it out.  Pretty sure the problem is on my end
>     > here �� I really mainly wanted to ask you if I was using the correct
>     > methods at this point, or if there was anything very obviously that I
>     > was doing wrong.
>     >
>     >
>     > Thanks a lot for your help!
>     >
>     >
>     > Andy
>     >
>     >
>     >
>     >
>     >
>     >
>     > ------------------------------------------------------------------------
>     > *From:* Karl Rupp <[email protected] <mailto:[email protected]>>
>     > *Sent:* Wednesday, July 20, 2016 5:00:36 PM
>     > *To:* Andrew Palumbo; viennacl-devel
>     > *Subject:* Re: [ViennaCL-devel] Copying Values out of a 
> compressed_matrix
>     > Hi,
>     >
>     > please keep viennacl-devel in CC:
>     >
>     > Just to clarify: Do you get incorrect values for a 1-by-1 matrix as
>     > indicated in your sample data? In your previous email you mentioned that
>     > results are fine for small matrices...
>     >
>     > I'm afraid I can only guess at the source of the error with the
>     > informations provided. Any chance that you can provide a standalone code
>     > to reproduce the problem with reasonable effort?
>     >
>     > Best regards,
>     > Karli
>     >
>     >
>     >
>     > On 07/20/2016 10:16 PM, Andrew Palumbo wrote:
>     >> Thanks so much for your quick answer!
>     >>
>     >>
>     >> I actually am sorry to say that I made a mistake when writing the last
>     >> email, I copied the wrong signature from the VCL documentation, and 
> then
>     >> the mistake propagated through the rest of the e-mail.
>     >>
>     >>
>     >> I am actually using viennacl::backend::memory_read().
>     >>
>     >>
>     >> Eg, for the row_jumpers and column_idx  I read use:
>     >>
>     >> @Name("backend::memory_read")
>     >> public static native void memoryReadInt(@Const @ByRef MemHandle 
> src_buffer,
>     >>                                int bytes_to_read,
>     >>                                int offset,
>     >>                                IntPointer ptr,
>     >>                                boolean async);
>     >>
>     >> and for the Values:
>     >>
>     >>
>     >> @Name("backend::memory_read")
>     >> public static native void memoryReadDouble(@Const @ByRef MemHandle 
> src_buffer,
>     >>                                          int bytes_to_read,
>     >>                                          int offset,
>     >>                                          DoublePointer ptr,
>     >>                                          boolean async);
>     >>
>     >> And then call:
>     >>
>     >>
>     >> memoryReadInt(row_ptr_handle, (m +1) *4,0, row_ptr,false)
>     >> memoryReadInt(col_idx_handle, NNz *4,0,col_idx,false)
>     >> memoryReadDouble(element_handle, NNz *8,0, values,false)
>     >>
>     >>
>     >> and after convetring them to java.nio.Buffers, am getting results like:
>     >>
>     >>
>     >> rowBuff.get(1): 0    colBuff(1): 402653448 valBuff(1): 
> 6.91730177312166E-310
>     >>
>     >>
>     >> Have also tried reading into BytePointers similarly with the same type
>     >> of results.  I know that the use of Javacpp obfuscates what the problem
>     >> may be.  But I believe the Memorry is properly allocated.
>     >>
>     >>
>     >>
>     >> Sorry for the mistake.
>     >>
>     >>
>     >> Thanks,
>     >>
>     >>
>     >> Andy
>     >>
>     >>
>     >> 
> ------------------------------------------------------------------------
>     >> *From:* Karl Rupp <[email protected] 
> <mailto:[email protected]>>
>     >> *Sent:* Wednesday, July 20, 2016 3:50:07 PM
>     >> *To:* Andrew Palumbo;[email protected]
>     <mailto:[email protected]>
>     >> *Subject:* Re: [ViennaCL-devel] Copying Values out of a 
> compressed_matrix
>     >> Hi Andy,
>     >>
>     >> instead of viennacl::backend::memory_copy(), you want to use
>     >> viennacl::backend::memory_read(), which directly transfers the data 
> into
>     >> your buffer(s).
>     >>
>     >> If you *know* that your handles are in host memory, you can even grab
>     >> the values directly via
>     >>    viennacl::linalg::host_based::detail::extract_raw_pointer<T>();
>     >> defined in viennacl/linalg/host_based/common.hpp, around line 40.
>     >>
>     >> Please let me know if you still get errors after using that.
>     >>
>     >> Best regards,
>     >> Karli
>     >>
>     >>
>     >>
>     >>
>     >> On 07/20/2016 09:05 PM, Andrew Palumbo wrote:
>     >>> Hello,
>     >>>
>     >>>
>     >>> I'm Having some difficulties with compressed_matrix multiplication.
>     >>>
>     >>>
>     >>> Essentially I am copying  three buffers, the CSR conversion of an 
> Apache
>     >>> Mahout SparseMatrix, into two compressed_matrices performing matrix
>     >>> multiplication. I am doing this in scala and Java using javacpp.
>     >>>
>     >>>
>     >>> For example, I have a 5 x 10 matrix of ~20% non-zero values which in 
> CSR
>     >>> format looks like this:
>     >>>
>     >>>
>     >>> NNz: 12
>     >>>
>     >>> Row Pointer: [0, 1, 4, 6, 9, 12, ]
>     >>>
>     >>> Col Pointer: [9, 0, 8, 7, 2, 9, 0, 8, 9, 0, 3, 5, ]
>     >>>
>     >>> element Pointer: [0.4065367203992265, 0.04957158909682802,
>     >>> 0.5205586068847993, 0.3708618354358446, 0.6963900565931678,
>     >>> 0.8330915529787706, 0.32839112750638844, 0.7856168903297948,
>     >>> 0.4265801782090245, 0.14733066454561583, 0.9501663495824946,
>     >>> 0.9710498974366047, ]
>     >>>
>     >>> Multiplied by a similarly Sparse 10 x 5 compressed_matrix
>     >>>
>     >>> I use a CompressedMatrix wrapper which essentially wraps the
>     >>>
>     >>>      viennacl:: compressed_matrix (vcl_size_t rows, vcl_size_t cols,
>     >>> vcl_size_t nonzeros=0, viennacl::context ctx=viennacl::context())
>     >>>
>     >>> constructor as well as the
>     >>>
>     >>>      compressed_matrix (matrix_expression< const compressed_matrix,
>     >>> const compressed_matrix, op_prod > const &proxy).
>     >>>
>     >>> I have a helper function, /toVclCompressedMatrix/(..) which 
> essentially
>     >>> does the CSR conversion from a Mahout src matrix, calls the 
> constructor
>     >>> and uses viennacl::compressed_matrix::set(...) to set the buffers:
>     >>>
>     >>> val ompA =toVclCompressedMatrix(src = mxA, ompCtx)
>     >>> val ompB =toVclCompressedMatrix(src = mxB, ompCtx)
>     >>>
>     >>>
>     >>> and then create a new viennacl::compressed_matrix from the
>     >>> viennacl::linalg::prod of the 2 matrices i.e.:
>     >>>
>     >>> val ompC =new CompressedMatrix(prod(ompA, ompB))
>     >>>
>     >>> The context in the above case is either the Host or OpenMP (I know 
> that
>     >>> there is some special casting of the row_jumpers and col_idxs that 
> needs
>     >>> to be done in the OpenCL version)
>     >>>
>     >>> The Matrix multiplication completes without error on small Matrices 
> eg.
>     >>> < 300 x 300
>     >>> but seems to overwrite the resulting buffers on larger Matrices.
>     >>>
>     >>> My real problem, though is getting the memory back out of the
>     >>> resulting`ompC` compresed_matrix so that i can write it back to a 
> mahout
>     >>> SparseMatrix.
>     >>>
>     >>> currently I am using:
>     >>>
>     >>> void viennacl::backend::memory_copy (mem_handle const &  src_buffer,
>     >>>          mem_handle &      dst_buffer,
>     >>>          vcl_size_t      src_offset,
>     >>>          vcl_size_t      dst_offset,
>     >>>          vcl_size_t      bytes_to_copy
>     >>>      )
>     >>>
>     >>> on ompC.handel1,ompC.handel2 and ompC.handel source handels
>     >>>
>     >>> to copy into pre-allocated  row_jumper,  col_index and element buffers
>     >>> (of size ompC.size1() + 1, ompC.nnz and ompC.nnz, respectivly).
>     >>>
>     >>> I am getting nonsensical values back that one would expect from memory
>     >>> errors. eg:
>     >>>
>     >>> the Matrix geometry of the result: ompC.size1(), and omp.size2() are
>     >>> correct and ompC.nnz is a reasonable value.
>     >>>
>     >>> It is possible that I have mis-allocated some of the memory on my 
> side,
>     >>> but I am pretty sure that most of the Buffers are allocated correctly
>     >>> (usually JavaCPP does a pretty good job of this).
>     >>>
>     >>>
>     >>> I guess, long story short, my question is am i using the correct 
> method
>     >>> of copying the memory out of a compressed_matrix?  is there something
>     >>> glaringly incorrect that i am doing here?  Should I be using
>     >>> viennacl::backend::memory_copy or is there a different method that i
>     >>> should be using?
>     >>>
>     >>>
>     >>> Thanks very much,
>     >>>
>     >>> Andy
>     >>>
>     >>>
>     >>>
>     >>>
>     >>>
>     >>>
>     >>>
>     >>>
>     >>>
>     >>>
>     >>> 
> ------------------------------------------------------------------------------
>     >>> What NetFlow Analyzer can do for you? Monitors network bandwidth and 
> traffic
>     >>> patterns at an interface-level. Reveals which users, apps, and 
> protocols are
>     >>> consuming the most bandwidth. Provides multi-vendor support for 
> NetFlow,
>     >>> J-Flow, sFlow and other flows. Make informed decisions using capacity 
> planning
>     >>> reports.http://sdm.link/zohodev2dev
>     >>>
>     >>>
>     >>>
>     >>> _______________________________________________
>     >>> ViennaCL-devel mailing list
>     >>>[email protected]
>     <mailto:[email protected]>
>     >>>https://lists.sourceforge.net/lists/listinfo/viennacl-devel
>     >>>
>     >>
>     >
>
>
>     
> ------------------------------------------------------------------------------
>     What NetFlow Analyzer can do for you? Monitors network bandwidth and
>     traffic
>     patterns at an interface-level. Reveals which users, apps, and
>     protocols are
>     consuming the most bandwidth. Provides multi-vendor support for NetFlow,
>     J-Flow, sFlow and other flows. Make informed decisions using
>     capacity planning
>     reports.http://sdm.link/zohodev2dev
>     _______________________________________________
>     ViennaCL-devel mailing list
>     [email protected]
>     <mailto:[email protected]>
>     https://lists.sourceforge.net/lists/listinfo/viennacl-devel
>
>


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
ViennaCL-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/viennacl-devel

Reply via email to