Skip to content

Conversation

@li-roy
Copy link
Contributor

@li-roy li-roy commented Jun 19, 2019

Stack from ghstack:

In preparation of deleting Type. The getDeviceFromPtr logic is only used in from_blob, so I added _from_blob as a native function to dispatch the backend-based logic.

Differential Revision: D15893330

@pytorchbot pytorchbot added oncall: jit Add this issue/PR to JIT oncall triage queue module: autograd Related to torch.autograd, and the autograd engine in general module: cuda Related to torch.cuda, and CUDA support in general module: internals Related to internal abstractions in c10 and ATen module: operators module: pybind Related to our Python bindings / interactions with other Python libraries labels Jun 19, 2019
Remove getDeviceFromPtr and allocator from Type

gh-metadata: pytorch pytorch 21940 gh/li-roy/29/head
royboy added 2 commits June 19, 2019 10:46
Remove getDeviceFromPtr and allocator from Type

gh-metadata: pytorch pytorch 21940 gh/li-roy/29/head
Remove getDeviceFromPtr and allocator from Type

gh-metadata: pytorch pytorch 21940 gh/li-roy/29/head
@li-roy li-roy requested review from dzhulgakov, ezyang, gchanan and smessmer and removed request for gchanan June 19, 2019 19:23


blacklisted_types = {'Storage', 'DimnameList?', 'ConstQuantizerPtr'}
blacklisted_types = {'Storage', 'DimnameList?', 'ConstQuantizerPtr', 'void*', 'std::function<void(void*)>'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really an issue with this diff, but doesn't the fact that you need to blacklist mean that the JIT is ignoring which functions aren't exposed to python? Which means if it's composed of all non-blacklisted-types I can use it in JIT but can't in frontend? That doesn't seem great.

CPU: _frac_out_cpu
CUDA: _frac_out_cuda

- func: _from_blob(void* data, int[] sizes, int[] strides, std::function<void(void*)> deleter, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem like the best solution, because native_functions is supposed to basically be python and now you need to teach codegen about these crazy things like std::function<void(void*)> deleter just to get type-dispatch.

Can we just hardcode this function in your registration table, i.e. just make it the equivalent of type? Because its' really just implementation detail stuff that doesn't need to be in native_functions (outside dispatch).

@ezyang ezyang removed their request for review June 20, 2019 14:02
@ezyang
Copy link
Contributor

ezyang commented Jun 20, 2019

deferring to @gchanan for this one

@gchanan
Copy link
Contributor

gchanan commented Jun 20, 2019

based on a chat with @li-roy I believe the current thinking is to put the minimal needed functionality onto Context (find the device for a pointer given deviceType), similar to defaultGenerator (

Generator & defaultGenerator(Device device) {
DeviceType device_type = device.type();
initCUDAIfNeeded(device_type);
initHIPIfNeeded(device_type);
if (device_type == at::kCPU) {
return *at::detail::getDefaultCPUGenerator();
} else if (device_type == at::kCUDA) {
return *at::detail::getCUDAHooks().getDefaultCUDAGenerator(device.index());
} else {
AT_ERROR(DeviceTypeName(device_type), " backend type not enabled.");
}
}
).

@gchanan
Copy link
Contributor

gchanan commented Jun 20, 2019

The advantage being that we don't need to teach codegen about C++ specific things like std::function<void(void*)> and we don't need to hardcode things into the dispatch table.

Remove getDeviceFromPtr and allocator from Type

gh-metadata: pytorch pytorch 21940 gh/li-roy/29/head
}

virtual Device getDeviceFromPtr(void* data) const {
AT_ERROR("Cannot get default CUDA device without ATen_cuda library. ", CUDA_HELP);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error message doesn't seem correct.

Copy link
Contributor

@gchanan gchanan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just fix the error message, I think.

royboy added 2 commits June 20, 2019 15:31
Remove getDeviceFromPtr and allocator from Type

gh-metadata: pytorch pytorch 21940 gh/li-roy/29/head
Remove getDeviceFromPtr and allocator from Type

gh-metadata: pytorch pytorch 21940 gh/li-roy/29/head
@zou3519 zou3519 deleted the gh/li-roy/29/head branch June 21, 2019 08:08
zdevito pushed a commit to zdevito/ATen that referenced this pull request Jun 21, 2019
Summary:
Pull Request resolved: pytorch/pytorch#21940
ghimport-source-id: 0a618878ae030f663b05662f83ac4b549a90ba29

Test Plan: Imported from OSS

Differential Revision: D15893330

Pulled By: li-roy

fbshipit-source-id: a3dfb6b4ed0c72f7f3efd00192fb63aabc9c5967
@facebook-github-bot
Copy link
Contributor

@li-roy merged this pull request in edb5a16.

iotamudelta pushed a commit to ROCm/pytorch that referenced this pull request Jun 21, 2019
Summary:
Pull Request resolved: pytorch#21940
ghimport-source-id: 0a61887

Test Plan: Imported from OSS

Differential Revision: D15893330

Pulled By: li-roy

fbshipit-source-id: a3dfb6b4ed0c72f7f3efd00192fb63aabc9c5967
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: autograd Related to torch.autograd, and the autograd engine in general module: cuda Related to torch.cuda, and CUDA support in general module: internals Related to internal abstractions in c10 and ATen module: pybind Related to our Python bindings / interactions with other Python libraries oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants