()
| 145 | |
| 146 | |
| 147 | def monkey_patch_value(): |
| 148 | def safe_get_dtype(var): |
| 149 | try: |
| 150 | dtype = var.dtype |
| 151 | except: |
| 152 | raise ValueError("Cannot get data type from var") |
| 153 | return dtype |
| 154 | |
| 155 | def cpu(self): |
| 156 | """ |
| 157 | In dy2static, Tensor also needs cpu() and cuda() interface. |
| 158 | But, the underneath operator has only forward op but not backward one. |
| 159 | |
| 160 | Returns: |
| 161 | The tensor which has copied to cpu place. |
| 162 | |
| 163 | Examples: |
| 164 | In Static Graph Mode: |
| 165 | |
| 166 | .. code-block:: pycon |
| 167 | |
| 168 | >>> import paddle |
| 169 | >>> paddle.enable_static() |
| 170 | |
| 171 | >>> x = paddle.static.data(name="x", shape=[2, 2], dtype='float32') |
| 172 | >>> y = x.cpu() |
| 173 | """ |
| 174 | |
| 175 | # 0 means cpu place, see paddle/phi/kernels/memcpy_kernel.cc |
| 176 | return _C_ops.memcpy(self, 0) |
| 177 | |
| 178 | def cuda(self, device_id=None, blocking=True): |
| 179 | """ |
| 180 | In dy2static, Tensor also needs cpu() and cuda() interface. |
| 181 | But, the underneath operator has only forward op but not backward one. |
| 182 | |
| 183 | Args: |
| 184 | self(Tensor): The variable itself. |
| 185 | device_id(int, optional): The destination GPU device id. Default: None, means current device. |
| 186 | We add this argument for dy2static translation, please do not use it. |
| 187 | blocking(bool, optional): Whether blocking or not, Default: True. |
| 188 | We add this argument for dy2static translation, please do not use it. |
| 189 | |
| 190 | Returns: |
| 191 | The tensor which has copied to cuda place. |
| 192 | |
| 193 | Examples: |
| 194 | In Static Graph Mode: |
| 195 | |
| 196 | .. code-block:: pycon |
| 197 | |
| 198 | >>> import paddle |
| 199 | >>> paddle.enable_static() |
| 200 | |
| 201 | >>> x = paddle.static.data(name="x", shape=[2, 2], dtype='float32') |
| 202 | >>> y = x.cpu() |
| 203 | >>> z = y.cuda() |
| 204 | """ |
no test coverage detected