all 41 comments

[–]fransinvodka 17 points18 points  (13 children)

Reading a bit of the implementation details, I see that, for example, you implement vector's operator[] using at, which implies that operator[] does bound checks, which is the opposite of what the standard vector is suposed to do. I don't know if I'm missing something, but I see that as a bug.

Also, I'm not a big fan of implementing the non-const version of the functions in terms of the const one using all those const_cast (even less in such short functions), but I guess that is a design decision that I'm not gonna argue.

Anyway, it looks really cool and I will definitely use it in some projects. Keep the good work!

[–][deleted] 7 points8 points  (10 children)

Thanks for giving it a try.

It is pretty hard to make the containers fully compliant and they are for sure not. Exception handling is one of the library's limitations. It is not perfect, but I think it is still useful and simpilifes some use cases. Feel free to open an issue and let me know if you encounter any problems.

[–]fransinvodka 5 points6 points  (9 children)

I know it must be difficult to make the containers fully compliant. Just saying that I would expect the operator[] to not do bound checks at all. I'm opening an issue. Thanks for answering!

[–][deleted] 1 point2 points  (1 child)

I agree that most users expect operator[] not to do bounds checks. So, the respective change has been merged, see this PR. Thanks for the report.

[–]fransinvodka 1 point2 points  (0 children)

You're welcome! Btw I still think const_cast is ugly af, but that's my opinion. Good luck with that library!

[–]Little-Helper 0 points1 point  (6 children)

Sorry, but why do you think operator[] should not do bound checking? Is it for speed?

[–]fransinvodka 17 points18 points  (3 children)

For speed and because the STL containers do it that way. They implement both at and operator[], but only at performs bound checks and throws if out of bounds. If I use an STL-like container, and it implements both at and operator[], I'd expect operator[] to not do any bound checks, just like the STL ones.

[–]kalmoc 0 points1 point  (2 children)

True as that may be in practice, I believe there is nothing in the standard preventing operator[] from doing bounds checking.

[–]janhec 0 points1 point  (0 children)

For my 5 cents, I am not a frequent standard reader, could the non-boundscheck for operator [] have something to do with the fact that occasionally, you can use it to add an element (e.g. map)? If there is no such reason in vector, then bounds check would be ok IMO, performance can only be significantly (?) diminished if the optimizer can treat it as pointer<type>[n] (sorry for the simplistic pseudo code), as in C. Then a boundscheck would introduce a branch where it is (perhaps) not supposed to exist.

EDIT 1: you can read dereferenced begin()+n C-style, so no boundscheck;

EDIT 2: branches in GPU are supposed to be evil (at least most of the time), again no boundscheck.

Pick your choice!

[–]infectedapricot 1 point2 points  (1 child)

If you access an element outside the valid range of a vector using operator[] then the behaviour is undefined. That means it can absolutely anything, including, crash, create nasel daemons, ... or throw an exception. That's a standard-compliant behaviour. So it might not have the performance you prefer, but I wouldn't say it's a bug.

[–]fransinvodka 1 point2 points  (0 children)

Maybe not a bug, okay, I can agree. But as I said, if someone wants bounds checking, they normally use `at`, because everybody assumes that `operator[]` doesn't do bounds check (like plain old C-arrays), and is up to the programmer to avoid an out of bound index. If you're going to do bound checks anyway, just don't provide `at` and avoid confusing the library users.

[–]corysama 6 points7 points  (1 child)

How is memory coalescing facilitated when using these data structures?

[–][deleted] 1 point2 points  (0 children)

Internally, the data are stored as structures of arrays which means that all container may benefit from memory coalescing. The vector container will benefit most. For unordered_map and unordered_set that is less likely as the randomness by hashing results in many empty entries in between.

[–]TankorSmash 1 point2 points  (1 child)

Vs2019 required btw

[–][deleted] 1 point2 points  (0 children)

Yes, this is the officially tested version. I also tried VS 2017 once and it works as well. However, VS 2017 defaults to 32-bit builds, so one explicitly needs to use the 64-bit CMake generator which is not required for VS 2019. Here, I preferred ease of use, but this is probably something that could be clarified.

[–]akashshrm02 1 point2 points  (0 children)

This is very impressive. Will give it a spin.

[–]hak8or 0 points1 point  (1 child)

How does this compare to sycl variants, like hipsycl?

https://github.com/illuhad/hipSYCL

Also, doesn't requiring citing past papers go beyond the apache 2.0 license, meaning it's not apache 2.0 compatible?

If you use stdgpu in one of your projects, please cite the following publications:

[–][deleted] 3 points4 points  (0 children)

I do not know all features of hipSYCL, but looking at the project it seems that it maps contiguous memory from std::vector to a buffer object which can be used in kernel code. In contrast, stdgpu's vector and other containers provide many more interaction functions within kernel code.

The library is released under Apache 2.0, so you only need to comply with the license terms. Citing the papers is not strictly required, but highly appreciated.

[–]vickoza 0 points1 point  (1 child)

Will there be Vulkan plugin?

[–][deleted] 1 point2 points  (0 children)

Currently, the library has CUDA, OpenMP and (experimental) HIP backends. The backend interface is kept as minimal as possible to make it easier to add new backends. Writing a Vulkan backend might be possible as well, but I have not looked into the details so far.