to

copy variable into the other device (e.g., CPU -> CUDA or CUDA -> CPU)

  1. auto to(T[] src)
  2. auto to(Src src)
  3. Variable!(T, dim, Dst) to(Variable!(T, dim, Src) src)
    Variable!(T, dim, Dst)
    to
    (
    alias Dst
    T
    size_t dim
    alias Src
    )
    (
    Variable!(T, dim, Src) src
    )

Examples

import std.stdio;

{
    // Variable!(float, 1) x;
    auto x = [-1f, -2f, -3f].variable;
    auto y = x.dup;
    x.data[0] = 1.0;
    static assert(isVariable!(typeof(x)));
    static assert(!isVariable!void);
    static assert(isHost!(typeof(x)));
    assert(y.data[0] == -1);
}
version (grain_cuda) {
    {
        auto x = [[1f, 3f], [5f, 7f], [9f, 11f]].variable;

        assert(x.data.length == 6);
        static assert(!isHost!(typeof(x.to!DeviceStorage)));
        auto xx = x.dup;
        assert(x.to!DeviceStorage
                .to!HostStorage
                .sliced == x.sliced);
    }
}

Meta