Hey, this is quite a tricky thing, so let me elaborate a bit:
** Prelude ** Conceptually, an index access like my_vector[i] = 42; expects i to be a size_t (there are even some notes on performance implications in some optimization guides). Okay, so let's look at the more general case of strided access with offset: my_vector[start + i * stride] = 42; Currently, we internally deal with 'start' and 'stride' such that they are both unsigned integer types (size_t), so we can nicely use the same type for i. ** The Problems ** The first thing is a portability problem with OpenMP: The implementations in Visual Studio up to (I think) 2010 only support signed integer types, so if 'i' is the loop variable, then 'i' cannot be size_t. This is where the big mess in terms of casting starts. The second problem is that of negative strides, which are handy for certain operations such as reversing a vector, as Philippe noted. This, on the other hand, means that any index calculation like start + i * stride with 'start' being unsigned and 'stride' being signed requires at least one cast. The C conversion rules mandate that 'stride' is first converted to unsigned if the explicit cast is forgotten, so this is all *very* likely to result in awful runtime bugs for negative strides, which are very hard to cover with automated tests. This is particularly an issue for contributed code, as we must not expect contributors to know ViennaCL in all details. Then, there's also the issue with Fortran: As the language only introduced unsigned integers recently, there's tons of legacy code that only uses signed integers. So, if we want to push libviennacl, we have to provide an interface based on signed integers. Once we buy into this, it's worth a thought to switch to signed index variables completely. For anything other than matrix-matrix multiplications, I expect that this does not have a notable performance implication. Probably it does not have a notable influence for matrix-matrix multiplications either, but Philippe has more experience on this. Note that we can always use unsigned types inside the kernel if required. ** Solutions? ** Frankly, I'm leaning towards using signed integer types everywhere, even if this is a bit unusual for the C++ world. However, I think it's still worth it in order to a) simplify the types involved (no thinking about signed vs. unsigned) b) avoid tons of casts due to signed/unsigned conversions. c) have better compatibility with BLAS and other languages, particularly Fortran If we are really wild about being C++ish, we can think about an integer-index'ed shared library core for ViennaCL 2.0.0 and then wrap/cast the respective indices to unsigned types for a high-level C++ layer just like what we have now. Still sounds messy and unnecessary complicated, though... Any thoughts on this? Best regards, Karli On 07/02/2014 09:14 PM, Philippe Tillet wrote: > Hi again, > > It seems like the BLAS standard allows negative stride, but judging from > all the implicit conversions happening, I don't think that it is well > supported in ViennaCL. In order to avoid loss of bits, it seems like my > cblas.h header uses signed int for both the strides and the offset/size. > Perhaps we should do the same thing? > > > 2014-07-02 18:54 GMT+02:00 Philippe Tillet <phil.til...@gmail.com > <mailto:phil.til...@gmail.com>>: > > Hello, > > While fixing some warnings I have noticed an inconsistency in the > type of strides. > > matrices/vectors use difference_type > traits::stride use size_type > > This is a serious warnings because it leaves an ambiguity on > negative strides. > I think that negative strides should be allowed, as it allows to > simply "reverse" a vector: (by using range(N, N), stride = -1). But > I'm not sure our assertions (or the rest of the core) would actually > properly support it. > > I think we should use difference type, anyway, since strides are > conceptually differences. > > Philippe > > > > > ------------------------------------------------------------------------------ > Open source business process management suite built on Java and Eclipse > Turn processes into business applications with Bonita BPM Community Edition > Quickly connect people, data, and systems into organized workflows > Winner of BOSSIE, CODIE, OW2 and Gartner awards > http://p.sf.net/sfu/Bonitasoft > > > > _______________________________________________ > ViennaCL-devel mailing list > ViennaCL-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/viennacl-devel > ------------------------------------------------------------------------------ Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards http://p.sf.net/sfu/Bonitasoft _______________________________________________ ViennaCL-devel mailing list ViennaCL-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/viennacl-devel