Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add to/from pointer #1473

Merged
merged 12 commits into from
Apr 25, 2024
Merged

feat: add to/from pointer #1473

merged 12 commits into from
Apr 25, 2024

Conversation

polvalente
Copy link
Contributor

Enables pointer manipulation for sharing CUDA memory between processes in EXLA.
In theory, IPC can also be supported for host-allocated memory, but this is not implemented yet.
It is also possible to use local (as in, "same process") pointers through these functions,
albeit there's not much gain besides automated testing.

@polvalente polvalente self-assigned this Apr 25, 2024
@polvalente polvalente force-pushed the pv-feat/add-input-output-pointer branch from 57a3d0a to 681f436 Compare April 25, 2024 06:57
exla/Makefile Outdated
@@ -1,4 +1,4 @@
# Environment variables passed via elixir_make
# Environment variables passed via elixir_make
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Environment variables passed via elixir_make
# Environment variables passed via elixir_make

nx/lib/nx.ex Outdated
>
"""
@doc type: :creation
def from_pointer(backend, opaque_pointer, type, shape, opts \\ []) when is_atom(backend) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I gave bad advice. The backend should be an option, similar to how it is done in from_binary. :) So there is a single option called :backend.

Regarding the backend options, we could simplify proxy everything else to the backend. Or we should call it pointer_options to avoid confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like backend being an option here because it is mandatory and there's no sensible default we can have.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that pointer_options is a better name! Will change both in the next commit

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you want to force the backend, then it should mirror the API from backend_transfer, where the backend is either an atom or a two-element tuple. Also note the examples above are incorrect (they are not passing the backend as first argument).

nx/lib/nx.ex Outdated

## Options

All options are backend-specific
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
All options are backend-specific
All options are backend-specific.

We may also nest everything under pointer_options to avoid confusion.

def from_pointer(pointer, type, dims, opts) do
template = Nx.template(dims, type, names: opts[:names])

opts = Keyword.validate!(opts[:backend_opts] || [], [:client_name, :device_id, mode: :local])
Copy link
Collaborator

Choose a reason for hiding this comment

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

As commented below, this is mixing backend options (such as client name) with pointer options. We probably should treat them separately.

Comment on lines 166 to 171
raise ArgumentError, "#{__MODULE__} does not support pointer manipulation"
end

@impl true
def to_pointer(_, _) do
raise ArgumentError, "#{__MODULE__} does not support pointer manipulation"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
raise ArgumentError, "#{__MODULE__} does not support pointer manipulation"
end
@impl true
def to_pointer(_, _) do
raise ArgumentError, "#{__MODULE__} does not support pointer manipulation"
raise ArgumentError, "#{inspect(__MODULE__)} does not support pointer manipulation"
end
@impl true
def to_pointer(_, _) do
raise ArgumentError, "#{inspect(__MODULE__)} does not support pointer manipulation"

@polvalente polvalente merged commit c6f8cec into main Apr 25, 2024
8 checks passed
@polvalente polvalente deleted the pv-feat/add-input-output-pointer branch April 25, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants