Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Bundle datatype seemingly doesn't need the field sVector #269

Open
gksato opened this issue Jan 26, 2020 · 14 comments
Open

The Bundle datatype seemingly doesn't need the field sVector #269

gksato opened this issue Jan 26, 2020 · 14 comments

Comments

@gksato
Copy link
Contributor

gksato commented Jan 26, 2020

In the module Data.Vector.Fusion.Bundle.Monadic, the datatype Bundle m v a has the field sVector :: Maybe (v a), whose value is currently used by no consumer, apparently (by which I mean I didn't find any usage when I scanned through the code). I am just curious how come it's there. For what (practical or historical) reason does the field exist? Is it even OK to make a pull request in favor of its removal?

@gksato gksato changed the title Bundle seemingly doesn't need the field sVector The Bundle datatype seemingly doesn't need the field sVector Jan 26, 2020
@cartazio
Copy link
Contributor

cartazio commented Jan 26, 2020 via email

@gksato
Copy link
Contributor Author

gksato commented Jan 26, 2020

At least one generator does generate Just v: Data.Vector.Fusion.Bundle.Monadic.fromVector (and hence so do Data.Vector.Generic.stream and Data.Vector.Fusion.Bundle.fromVector). Also, Data.Vector.Fusion.Bundle.Monadic.trans preserves the value of the field. If I've read through and searched within the code correctly, they are the only functions that can give Bundle having Just in sVector.

@gksato
Copy link
Contributor Author

gksato commented Jan 26, 2020

Oops. There's Data.Vector.Generic.stream', of course! ;)

@cartazio
Copy link
Contributor

all good :)

@gksato
Copy link
Contributor Author

gksato commented Jan 31, 2020

I don't understand why this has got closed. Could you explain why? My point is that someone assigns it, but nobody uses it. Maybe for use from other package?

@cartazio
Copy link
Contributor

cartazio commented Jan 31, 2020 via email

@gksato
Copy link
Contributor Author

gksato commented Jan 31, 2020

My point is: some agents (Generic.stream, Generic.stream', Bundle.Monadic.fromVector and Bundle.fromVector) give a value to it, other (Bundle.Monadic.trans and Bundle.lift) leave the value in it as it is, but if I eye-grepped right, nobody takes a value out of it.

@cartazio cartazio reopened this Jan 31, 2020
@cartazio
Copy link
Contributor

cartazio commented Jan 31, 2020 via email

@gksato
Copy link
Contributor Author

gksato commented Jan 31, 2020

There are some options I can think of:
1: We could add some consumption: unstreaming operation, slicing operation, and indexing may take the vector out of sVector. There may or may not be performance penalty. I'm pretty doubtful there will be performance benefit. (I say "doubtful"; I didn't test.)
2: We could entirely remove sVector. May get a slight performance benefit?
3: Leave it as it is. I don't say this is a very good choice. However it's not an utterly bad option, if you think of Data.Vector.Fusion as non-internal. In fact, I found this issue when I was writing Stream Fusion code outside of vector.
4: I am wrong. My eye-grep is buggy and there's an usage I didn't find, or the field is some mysterious magic getting the whole thing blazing fast ;)

@Shimuuar Shimuuar mentioned this issue Jan 17, 2021
6 tasks
@lehins
Copy link
Contributor

lehins commented Jan 17, 2021

The whole reason why Bundle was created is to utilize SIMD instructions. It is described in this paper: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/07/haskell-beats-C.pdf
At some point, I think, there was a fork of vector that worked with some fork of GHC that was actually able to utilize CPU vectorization, but currently this is not the case and I believe sVector isn't used for anything constructive

So, what do we do about it?

  • We could put effort into removing it, but I highly doubt that we get any performance benefit out of it, maybe only compilation times will improve. It is important to realize, however, that there is a huge danger of introducing new bugs in undertaking like this.
  • We could leave it as is and wait until ghc acquires native SIMD support, and try to finish what the research in the paper has started

I am leaning towards the latter.

CC @Shimuuar This is my opinion on this issue, since it came up in the release plan.

Linking #251 as related ticket on the subject.

@gksato
Copy link
Contributor Author

gksato commented Jan 17, 2021

@lehins Oh, as an author of this issue, let me mention #330! (Sorry I'm so lazy).

@lehins
Copy link
Contributor

lehins commented Jan 17, 2021

Oh, yeah, I forgot that we found a use for sVector 😉

So, let's keep this issue open, but without any rush of removing sVector and Bundle restructure, who knows what other uses we can find for it.

@Bodigrim
Copy link
Contributor

Let's keep sVector then.

@cartazio
Copy link
Contributor

cartazio commented Jan 17, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants