1 import std.stdio; 2 3 { 4 // Variable!(float, 1) x; 5 auto x = [-1f, -2f, -3f].variable; 6 auto y = x.dup; 7 x.data[0] = 1.0; 8 static assert(isVariable!(typeof(x))); 9 static assert(!isVariable!void); 10 static assert(isHost!(typeof(x))); 11 assert(y.data[0] == -1); 12 } 13 version (grain_cuda) { 14 { 15 auto x = [[1f, 3f], [5f, 7f], [9f, 11f]].variable; 16 17 assert(x.data.length == 6); 18 static assert(!isHost!(typeof(x.to!DeviceStorage))); 19 auto xx = x.dup; 20 assert(x.to!DeviceStorage 21 .to!HostStorage 22 .sliced == x.sliced); 23 } 24 }
copy variable into the other device (e.g., CPU -> CUDA or CUDA -> CPU)