Skip to content

On GPU: Multiplication of array * scalar != scalar * array #119

@aoeftiger

Description

@aoeftiger

This "feature" of Python can lead to bugs in PyHEADTAIL on the GPU when developing new modules, need to keep this in mind for the future (all current modules in PyHEADTAIL work fine normally!):

Basis: e.g. a * b calls the operator __mul__ of a. Vice versa, b * a calls the operator __mul__ of b.

Take a to be a pycuda.GPUArray of some length (typically e.g. the beam.x array on the GPU) and b to be a scalar / single number stored in a pycuda.GPUArray of length 1.

In PyHEADTAIL on the GPU, a * b now provides an array of length a.shape while b * a leads to a length 1 output. I.e. all contents of a have been swallowed...

PyHEADTAIL monkeypatches PyCUDA to deal with a * b (kudos to @Stefannn ) but b * a will lead to mostly unwanted behaviour. (The monkey patching:

# patch the GPUArray to be able to cope with gpuarrays of size 1 as ops
)

==> we should cleanly fix this at some point! It's there since the very beginning...

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