MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / copy_variable

Function copy_variable

src/models/model.cc:125–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123 }
124
125 static StorageView copy_variable(const StorageView& variable,
126 const Device device, const int device_index) {
127 if (variable.is_scalar() || (variable.device() == Device::CPU && device == Device::CPU))
128 return variable;
129
130 StorageView copy;
131
132 if (variable.device() != Device::CPU) {
133 ScopedDeviceSetter scoped_device_setter(variable.device(), variable.device_index());
134 copy = variable.to(Device::CPU);
135 }
136
137 if (device != Device::CPU) {
138 ScopedDeviceSetter scoped_device_setter(device, device_index);
139 if (copy)
140 copy = copy.to(device);
141 else
142 copy = variable.to(device);
143 }
144
145 return copy;
146 }
147
148
149 std::unique_ptr<SequenceToSequenceReplica> Model::as_sequence_to_sequence() const {

Callers 1

copy_toMethod · 0.85

Calls 4

is_scalarMethod · 0.45
deviceMethod · 0.45
device_indexMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected