Skip to content

Flux.cpu and Flux.gpu no longer move data on views #2553

@piever

Description

@piever

Currently (as of Flux 0.15), Flux.cpu and Flux.gpu do not error when fed a view, but they simply return an identical value, without moving data to / from the GPU.

MWE

julia> using Flux, CUDA, cuDNN

julia> cpu_view = view(rand(2, 2), 1, :);

julia> gpu_view = view(CUDA.rand(2, 2), 1, :);

julia> Flux.gpu(cpu_view)
2-element view(::Matrix{Float64}, 1, :) with eltype Float64:
 0.10101004098832933
 0.7891135815339817

julia> Flux.cpu(gpu_view)
2-element view(::CuArray{Float32, 2, CUDA.DeviceMemory}, 1, :) with eltype Float32:
 0.5095508
 0.93324655

Dependencies:

  [052768ef] CUDA v5.5.2
  [587475ba] Flux v0.15.2
  [02a925ec] cuDNN v1.4.0

on Julia 1.11.2

On Flux 0.14, Flux.cpu and Flux.gpu would transform views by applying the transformation to the parent array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions