diff mbox series

[bug#58100] gnu: cbqn: factor out singeli into derivative package.

Message ID 20220926191212.30609-1-yewscion@gmail.com
State New
Headers show
Series [bug#58100] gnu: cbqn: factor out singeli into derivative package. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Christopher Rodriguez Sept. 26, 2022, 7:12 p.m. UTC
Persuant to a recent conversation[1] with upstream, I've factored the
AVX2-dependent builds into their own package (defaulting to a generic build
instead).

+ gnu/packages/bqn.scm: cbqn-singeli
~ gnu/packages/bqn.scm: cbqn: changed make flags, inputs, and commit.
---
 gnu/packages/bqn.scm | 45 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 39 insertions(+), 6 deletions(-)

Comments

Christopher Rodriguez Sept. 26, 2022, 7:17 p.m. UTC | #1
Christopher Rodriguez <yewscion@gmail.com> writes:

> Persuant to a recent conversation[1] with upstream, I've factored the
> AVX2-dependent builds into their own package (defaulting to a generic build
> instead).

Sorry, forgot to actually include the link.

This change came from this[1] discussion with upstream, and this[2]
discussion on IRC.

[1]: https://github.com/dzaima/CBQN/issues/45#issuecomment-1258330937
[2]: https://logs.guix.gnu.org/guix/2022-09-26.log#191521
Liliana Marie Prikler Sept. 27, 2022, 7:26 a.m. UTC | #2
Am Montag, dem 26.09.2022 um 15:12 -0400 schrieb Christopher Rodriguez:
> Persuant to a recent conversation[1] with upstream, I've factored the
> AVX2-dependent builds into their own package (defaulting to a generic
> build
> instead).
> 
> + gnu/packages/bqn.scm: cbqn-singeli
> ~ gnu/packages/bqn.scm: cbqn: changed make flags, inputs, and commit.
This is not how to write a ChangeLog.  See [1] or infer from other
commits.

> ---
>  gnu/packages/bqn.scm | 45 ++++++++++++++++++++++++++++++++++++++----
> --
>  1 file changed, 39 insertions(+), 6 deletions(-)
> 
> diff --git a/gnu/packages/bqn.scm b/gnu/packages/bqn.scm
> index c4e0f39efb..56705beede 100644
> --- a/gnu/packages/bqn.scm
> +++ b/gnu/packages/bqn.scm
> @@ -126,7 +126,7 @@ (define bqn-sources
>  
>  (define cbqn-bootstrap
>    (let* ((revision "1")
> -         (commit "9c1cbdc99863b1da0116df61cd832137b196dc5c"))
> +         (commit "bd823839feaf42af4013e5a245981f58f563e659"))
Why are you changing the bootstrap commit?  This looks suspicious.
>      (package
>        (name "cbqn-bootstrap")
>        (version (git-version "0" "1" commit))
> @@ -138,7 +138,7 @@ (define cbqn-bootstrap
>                  (file-name (git-file-name name version))
>                  (sha256
>                   (base32
> -                 
> "0w38fhwf20drkyijy6nfnhmc5g5gw0zmzgmy1q605x57znlj85a2"))))
> +                 
> "0735mixvpgp2g1jsmbg7aaw35r4xs348y7djkwdvb0193ais6xz2"))))
>        (build-system gnu-build-system)
>        (arguments
>         (list #:tests? #f                         ;skipping tests for
> bootstrap
> @@ -182,12 +182,9 @@ (define-public cbqn
>      (name "cbqn")
>      (outputs '("out" "lib"))
>      (arguments
> -     (list #:make-flags '(list "shared-o3" "o3n-singeli")
> +     (list #:make-flags '(list "shared-o3" "o3")
Okay
>             #:phases #~(modify-phases %standard-phases
>                          (delete 'configure)
> -                        (add-before 'build 'link-singeli
> -                          (lambda* (#:key inputs #:allow-other-keys)
> -                            (symlink #+singeli-sources "Singeli")))
>                          (add-before 'build 'generate-bytecode
>                            (lambda* (#:key inputs #:allow-other-keys)
>                              (system (string-append #+dbqn
> @@ -222,3 +219,39 @@ (define-public cbqn
>                           libffi
>                           clang-toolchain
>                           linux-libre-headers))))
> +(define-public cbqn-singeli
> +  (package
> +    (inherit cbqn)
> +    (name "cbqn-singeli")
> +    (outputs '("out"))
> +    (arguments
> +     (list #:make-flags '(list "singeli=1 f='-mavx2 -mbmi2 -O3' c")
> +           #:phases #~(modify-phases %standard-phases
> +                        (delete 'configure)
> +                        (add-before 'build 'link-singeli
> +                          (lambda* (#:key inputs #:allow-other-keys)
> +                            (symlink #+singeli-sources "Singeli")))
> +                        (add-before 'build 'generate-bytecode
> +                          (lambda* (#:key inputs #:allow-other-keys)
> +                            (system (string-append #+dbqn
> +                                                   "/bin/dbqn
> ./genRuntime "
> +                                                   #+bqn-sources))))
> +                        (replace 'check
> +                          (lambda* (#:key inputs tests? #:allow-
> other-keys)
> +                            (when tests?
> +                              (system (string-append "./BQN -M 1000
> \""
> +                                                     #+bqn-sources
> +                                                    
> "/test/this.bqn\""))
> +                              (map (lambda (x)
> +                                     (system (string-append "./BQN
> ./test/" x
> +                                                           
> ".bqn")))
> +                                   '("cmp" "equal" "copy"
> "random")))))
> +                        (replace 'install
> +                          (lambda* (#:key outputs #:allow-other-
> keys)
> +                            (let* ((bin (string-append (assoc-ref
> outputs
> +                                                                 
> "out")
> +                                                       "/bin")))
> +                              (mkdir-p bin)
> +                              (copy-recursively "BQN"
> +                                                (string-append bin
> "/bqn"))))))))))
> +
Instead of providing a singeli variant, would just tuning the package
suffice?  If not, I think we should try to properly unbundle singeli
(as in build an actual singeli package) before adding another package
variant.  Then, you could use existing patterns to decide whether to
use singeli by making it an input or not.

Cheers

[1] https://www.gnu.org/prep/standards/html_node/Change-Logs.html
Christopher Rodriguez Sept. 27, 2022, 5:27 p.m. UTC | #3
Liliana Marie Prikler <liliana.prikler@ist.tugraz.at> writes:

> This is not how to write a ChangeLog.  See [1] or infer from other
> commits.

Thank You for pointing me in the right direction; I will ensure a
standardized changelog in my revised patch after reading all of the
linked info.

>> -         (commit "9c1cbdc99863b1da0116df61cd832137b196dc5c"))
>> +         (commit "bd823839feaf42af4013e5a245981f58f563e659"))
> Why are you changing the bootstrap commit?  This looks suspicious.

I am bumping the commit from 9c1cbdc99863b1da0116df61cd832137b196dc5c to
46501ac819c8f21c69d7d2ba4b0457a7356f5e42 (another commit was made when
closing the above-linked issue) as the new commit is the most recent one
for this un-tagged project.

There is no 'release' to package, and so in order to stay up to date
regular updates of this package's commit will likely be necessary.

I can see why the bootstrap commit might stay the same, however. Would
it be better to solely amend the commit on the actual installable
package instead?

>>      (arguments
>> -     (list #:make-flags '(list "shared-o3" "o3n-singeli")
>> +     (list #:make-flags '(list "shared-o3" "o3")
> Okay

I have actually just re-read the documentation after the abovementioned
most recent commit, and noticed a surviving line in the upstream
`README.md`[1]:

`make PIE=""` on ARM CPUs (incl. Android & M1)

Perhaps I can incorporate this into the package to allow it to build on
aarch64 as well as x86_64? Though as mentioned in the original upstream
issue, I think there is a problem with a dependent package… perhaps this
should be saved for a separate issue, then.

> Instead of providing a singeli variant, would just tuning the package
> suffice?
This was actually my biggest question when making the patch. I chose a
singeli variant because there is no architecture detection at all in the
makefile; it relies entirely on the specified targets ("o3", "c", etc)
to decide what to build for.

As an example: Switching the target from "o3n-singeli" to "o3"
immediately changed the entire build, preventing it from looking at all
for Singeli sources, even though I had yet to unlink them from the
source directory.

Is there a preferred method for this kind of build structure in a Guix
package? I suppose I could do a (cond *) in the make flags… maybe
referencing a variable for the target? I don't know what variable that
might be, though, as we would not only be looking for an x86_64 target,
but specifically that the underlying system supports AVX2…

In general, I would much prefer to keep it as one package. I think it is
much easier to maintain that way, and makes the user experience much
easier as well. But I'm sorry to report that I'm unaware of how best to
implement this, and would greatly appreciate some advice.

> If not, I think we should try to properly unbundle singeli (as in
> build an actual singeli package) before adding another package
> variant.  Then, you could use existing patterns to decide whether to
> use singeli by making it an input or not.

As for unbundling singeli: Running singeli requires a version of cbqn
built with or without singeli support. Building a version of cbqn with
singeli support requires the /source/ for singeli to be present in the
build directory at build time, not a precompiled binary. Singeli itself
is actually just a BQN script[2], and not a compiled binary at all, and
is a transpiler from BQN to IR/C. It's used in the optimized version to
transpile/compile the SIMD algorithms (sic, I am unfamiliar with this
concept).

In short, to unbundle singeli, we can just avoid including singeli in
the build, as in the revised cbqn package in the patch. We could make a
package for singeli that uses an installed bqn binary from any cbqn
package, but we would still need the sources present at build time due
to the way they are used and called in the build script. Fully
decoupling the optimized cbqn from singeli would require rewriting the
parts of the build that locate and run the singeli script, and (I think)
is more suited to an upstream patch than a package definition. I have
opened an issue regarding this possibility with upstream as of this
email[3].

(FWIW, I've also opened an issue regarding release tagging[4], though
from my previous correspondence with upstream I'm fairly certain a
release tag is not yet something they are comfortable with).

>
> Cheers

Thank You (as always) for Your guidance, Liliana. Sorry for these
issues, I am still learning best practices and standards for this
project and those of GNU in general. I hope You have a great day!

[1]: https://github.com/dzaima/CBQN/commit/46501ac819c8f21c69d7d2ba4b0457a7356f5e42
[2]: https://github.com/mlochbaum/Singeli/blob/master/singeli
[3]: https://github.com/dzaima/CBQN/issues/46
[4]: https://github.com/dzaima/CBQN/issues/47
Liliana Marie Prikler Sept. 28, 2022, 7:41 a.m. UTC | #4
Am Dienstag, dem 27.09.2022 um 13:27 -0400 schrieb Christopher
Rodriguez:
> I am bumping the commit from 9c1cbdc99863b1da0116df61cd832137b196dc5c
> to 46501ac819c8f21c69d7d2ba4b0457a7356f5e42 (another commit was made
> when closing the above-linked issue) as the new commit is the most
> recent one for this un-tagged project.
There is no policy in Guix to tail untagged projects. For personal
experimentation, use transformations, e.g. --with-branch. But even if
there is a good reason to bump the package, use a separate commit for
this.

> There is no 'release' to package, and so in order to stay up to date
> regular updates of this package's commit will likely be necessary.
Staying up to date is not good in and of itself, you have to evaluate
costs and benefits. Right now, you provided neither.

> I can see why the bootstrap commit might stay the same, however.
> Would it be better to solely amend the commit on the actual
> installable package instead?
I have no hard stance on this. While one could argue that it'd be
better for bootstrap binaries to be unmoving, this doesn't seem to
apply here. Other than that, it's better for bootstrap paths to be
short, see e.g. Rust. 

> > >      (arguments
> > > -     (list #:make-flags '(list "shared-o3" "o3n-singeli")
> > > +     (list #:make-flags '(list "shared-o3" "o3")
> > Okay
> 
> I have actually just re-read the documentation after the
> abovementioned most recent commit, and noticed a surviving line in
> the upstream `README.md`[1]:
> 
> `make PIE=""` on ARM CPUs (incl. Android & M1)
I'm pretty sure we'd like to specify e.g. -shared instead.

> Perhaps I can incorporate this into the package to allow it to build
> on aarch64 as well as x86_64? Though as mentioned in the original
> upstream issue, I think there is a problem with a dependent package…
> perhaps this should be saved for a separate issue, then.
It ought to at very least be a separate commit.

> > Instead of providing a  singeli variant, would just tuning the
> > package suffice?
> This was actually my biggest question when making the patch. I chose
> a singeli variant because there is no architecture detection at all
> in the makefile; it relies entirely on the specified targets ("o3",
> "c", etc) to decide what to build for.
That would be handled by the tuning compiler.

> As an example: Switching the target from "o3n-singeli" to "o3"
> immediately changed the entire build, preventing it from looking at
> all for Singeli sources, even though I had yet to unlink them from
> the source directory.
> 
> Is there a preferred method for this kind of build structure in a
> Guix package? I suppose I could do a (cond *) in the make flags…
> maybe referencing a variable for the target? I don't know what
> variable that might be, though, as we would not only be looking for
> an x86_64 target, but specifically that the underlying system
> supports AVX2…
> 
> In general, I would much prefer to keep it as one package. I think it
> is much easier to maintain that way, and makes the user experience
> much easier as well. But I'm sorry to report that I'm unaware of how
> best to implement this, and would greatly appreciate some advice.
My question is: what does singeli even do for cbqn?  If it's a
compiler, can you not simply run that compiler in a separate phase?

> > If not, I think we should try to properly unbundle singeli (as in
> > build an actual singeli package) before adding another package
> > variant.  Then, you could use existing patterns to decide whether
> > to use singeli by making it an input or not.
> 
> As for unbundling singeli: Running singeli requires a version of cbqn
> built with or without singeli support. Building a version of cbqn
> with singeli support requires the /source/ for singeli to be present
> in the build directory at build time, not a precompiled binary.
> Singeli itself is actually just a BQN script[2], and not a compiled
> binary at all, and is a transpiler from BQN to IR/C. It's used in the
> optimized version to transpile/compile the SIMD algorithms (sic, I am
> unfamiliar with this concept).
> 
> In short, to unbundle singeli, we can just avoid including singeli in
> the build, as in the revised cbqn package in the patch.
Good to know.

> We could make a package for singeli that uses an installed bqn binary
> from any cbqn package, but we would still need the sources present at
> build time due to the way they are used and called in the build
> script.
I'm pretty sure that finding the right arguments to copy-build-system
would be the first problem here.  As for the comment from dzaima, I
don't quite understand why you'd need two versions of cbqn.  Assume you
already have one built without singeli, how is it expected to change
once singeli is added?

> Fully decoupling the optimized cbqn from singeli would require
> rewriting the parts of the build that locate and run the singeli
> script, and (I think) is more suited to an upstream patch than a
> package definition. I have opened an issue regarding this possibility
> with upstream as of this email[3].
On that note, do you even need CBQN to run singeli or does any
(conforming) BQN implementation suffice?  For instance, you could try
building BQN with CBQN and then use that to run singeli, or use the
Java BQN.

> (FWIW, I've also opened an issue regarding release tagging[4], though
> from my previous correspondence with upstream I'm fairly certain a
> release tag is not yet something they are comfortable with).
That's fair and well, but to come back to the point made earlier, we
probably won't go to a newer commit unless there's an important
feature, bug fix, etc.  You can spend a lot of time optimizing without
substantially changing anything and trailing every single step on this
way would be a fool's errand.

Cheers

[1] https://github.com/dzaima/CBQN/issues/46#issuecomment-1259950602
diff mbox series

Patch

diff --git a/gnu/packages/bqn.scm b/gnu/packages/bqn.scm
index c4e0f39efb..56705beede 100644
--- a/gnu/packages/bqn.scm
+++ b/gnu/packages/bqn.scm
@@ -126,7 +126,7 @@  (define bqn-sources
 
 (define cbqn-bootstrap
   (let* ((revision "1")
-         (commit "9c1cbdc99863b1da0116df61cd832137b196dc5c"))
+         (commit "bd823839feaf42af4013e5a245981f58f563e659"))
     (package
       (name "cbqn-bootstrap")
       (version (git-version "0" "1" commit))
@@ -138,7 +138,7 @@  (define cbqn-bootstrap
                 (file-name (git-file-name name version))
                 (sha256
                  (base32
-                  "0w38fhwf20drkyijy6nfnhmc5g5gw0zmzgmy1q605x57znlj85a2"))))
+                  "0735mixvpgp2g1jsmbg7aaw35r4xs348y7djkwdvb0193ais6xz2"))))
       (build-system gnu-build-system)
       (arguments
        (list #:tests? #f                         ;skipping tests for bootstrap
@@ -182,12 +182,9 @@  (define-public cbqn
     (name "cbqn")
     (outputs '("out" "lib"))
     (arguments
-     (list #:make-flags '(list "shared-o3" "o3n-singeli")
+     (list #:make-flags '(list "shared-o3" "o3")
            #:phases #~(modify-phases %standard-phases
                         (delete 'configure)
-                        (add-before 'build 'link-singeli
-                          (lambda* (#:key inputs #:allow-other-keys)
-                            (symlink #+singeli-sources "Singeli")))
                         (add-before 'build 'generate-bytecode
                           (lambda* (#:key inputs #:allow-other-keys)
                             (system (string-append #+dbqn
@@ -222,3 +219,39 @@  (define-public cbqn
                          libffi
                          clang-toolchain
                          linux-libre-headers))))
+(define-public cbqn-singeli
+  (package
+    (inherit cbqn)
+    (name "cbqn-singeli")
+    (outputs '("out"))
+    (arguments
+     (list #:make-flags '(list "singeli=1 f='-mavx2 -mbmi2 -O3' c")
+           #:phases #~(modify-phases %standard-phases
+                        (delete 'configure)
+                        (add-before 'build 'link-singeli
+                          (lambda* (#:key inputs #:allow-other-keys)
+                            (symlink #+singeli-sources "Singeli")))
+                        (add-before 'build 'generate-bytecode
+                          (lambda* (#:key inputs #:allow-other-keys)
+                            (system (string-append #+dbqn
+                                                   "/bin/dbqn ./genRuntime "
+                                                   #+bqn-sources))))
+                        (replace 'check
+                          (lambda* (#:key inputs tests? #:allow-other-keys)
+                            (when tests?
+                              (system (string-append "./BQN -M 1000 \""
+                                                     #+bqn-sources
+                                                     "/test/this.bqn\""))
+                              (map (lambda (x)
+                                     (system (string-append "./BQN ./test/" x
+                                                            ".bqn")))
+                                   '("cmp" "equal" "copy" "random")))))
+                        (replace 'install
+                          (lambda* (#:key outputs #:allow-other-keys)
+                            (let* ((bin (string-append (assoc-ref outputs
+                                                                  "out")
+                                                       "/bin")))
+                              (mkdir-p bin)
+                              (copy-recursively "BQN"
+                                                (string-append bin "/bqn"))))))))))
+