FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

XSIMD implementation is slower than scalar performance with mixed precision operations · Issue #2881 · xtensor-stack/xtensor · GitHub

Repository navigation

XSIMD implementation is slower than scalar performance with mixed precision operations #2881

Open

Description

The following code performs operations on mixed types

    static void Xtensor_Uint16_2000x2000_DivideBy2Double_Xtensor(benchmark::State& aState)
    {
        xt::xtensor<uint16_t, 2> vInput = generateRandomInt16From0To100(cContainerAssignShape);
        auto vOutput = xt::xtensor<uint16_t, 2>::from_shape(cContainerAssignShape);

        for (auto _ : aState)
        {
            vOutput = vInput / 2.0;
        }
    }

When computing the expression, the result of uint16_t / int is an int. The resulting int then needs to be stored into vOutput as a uint16_t. As a result, std::copy is getting called in the inner loop inside load_aligned. The following code resolves this issue:

    static void Xtensor_Uint16_2000x2000_DivideBy2Double_Xtensor(benchmark::State& aState)
    {
        xt::xtensor<double, 2> vInput = generateRandomInt16From0To100(cContainerAssignShape);
        auto vOutput = xt::xtensor<double, 2>::from_shape(cContainerAssignShape);

        for (auto _ : aState)
        {
            vOutput = vInput / 2.0;
        }
    }

Is there a way to implement xsimd without copying data?

Activity

  1. JohanMabille commented on Jan 5, 2026

    Member

    Does it fix the issue if you explicitely cast the scalar to uint16_t ?

  2. spectre-ns commented on Jan 5, 2026

    ContributorAuthor

    Does it fix the issue if you explicitely cast the scalar to uint16_t ?

    It eliminates the simd assignment which does get rid of the copy but shouldn't we be able to vectorize the whole operation right?

  3. JohanMabille commented on Jan 6, 2026

    Member

    Ha indeed, I forgot not all architectures provide instruction for integer division. But then I'm a bit confused with "When computing the expression, the result of uint16_t / int is an int"; from what I understand it should compute uint16_t / double as a double, and then copy the result to uint16_t.

    Anyway, I'm afraid we cannot get rid of the conversion here, but maybe we could explore a different implementation of the load_aligned / store_aligned functions in xsimd, based on batch_cast instead of copying buffers. Not sure how faster it would be, though.

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

Metadata

Metadata

Assignees

No one assigned

    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


      Back | FazBrowse Home | New Git URL