Skip to content

truncation error fro simd vector size > 1 #209

Closed

Description

@sihyunjeon
diff --git a/madspace/src/cpu/simd_x86_256.hpp b/madspace/src/cpu/simd_x86_256.hpp
index 6c2815e25..fab1f9752 100644
--- a/madspace/src/cpu/simd_x86_256.hpp
+++ b/madspace/src/cpu/simd_x86_256.hpp
@@ -28,7 +28,7 @@ struct IVec {
     IVec() = default;
     IVec(__m256i _v) : v(_v) {};
     IVec(int _v) : v(_mm256_set1_epi64x(_v)) {};
-    explicit IVec(__m256d _v) { v = _mm256_cvtepi32_epi64(_mm256_cvtpd_epi32(_v)); }
+    explicit IVec(__m256d _v) { v = _mm256_cvtepi32_epi64(_mm256_cvttpd_epi32(_v)); }
     operator __m256i() { return v; }
     IVec operator+=(IVec _v) {
         v = _mm256_add_epi64(v, _v);
diff --git a/madspace/src/cpu/simd_x86_512.hpp b/madspace/src/cpu/simd_x86_512.hpp
index 1a7c97a98..74808d83c 100644
--- a/madspace/src/cpu/simd_x86_512.hpp
+++ b/madspace/src/cpu/simd_x86_512.hpp
@@ -21,7 +21,7 @@ struct IVec {
     IVec() = default;
     IVec(__m512i _v) : v(_v) {};
     IVec(int _v) : v(_mm512_set1_epi64(_v)) {};
-    explicit IVec(__m512d _v) { v = _mm512_cvtepi32_epi64(_mm512_cvtpd_epi32(_v)); }
+    explicit IVec(__m512d _v) { v = _mm512_cvtepi32_epi64(_mm512_cvttpd_epi32(_v)); }
     operator __m512i() { return v; }
     IVec operator+=(IVec _v) {
         v = _mm512_add_epi64(v, _v);

It looks like when using simd vector size with avx2, the numbers are rounded instead of being truncated

It doesn't correspond to scalar library case e.g. https://github.com/MadGraphTeam/MadGraph7/blob/main/madspace/src/kernels/discrete.hpp#L14

And I think above patch is the fix using cvttpd instead of cvtpd?

i ran p p > ve ve~ j and scalar was giving 838.7pb, simd_vector_size=4 was crashing before the change above with and gives me the same numerical result 838.7pb

Activity

  1. self-assigned this
    on Oct 7, 2026
  2. theoheimel commented on Oct 7, 2026

    @theoheimel
    Contributor

    Thanks for pointing this out! This is in madspace SIMD mode (i.e., only affects phase space sampling) which is currently still experimental and has several bugs. I'm working on it now in #222 . Note that the SIMD mode for the matrix elements (accessible through the cpu_mode parameter) is fully working, so we'll also make this distinction more clear in the run card.

  3. sihyunjeon commented on Oct 7, 2026

    @sihyunjeon
    Author

    @theoheimel thanks for covering this :) closing since it's addressed in your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions