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

Add MPS and XPU devices #125

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/ctorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ const auto get_device(torch_device_t device_type, int device_index)
<< std::endl;
exit(EXIT_FAILURE);
}
case torch_kMPS:
if (device_index != -1 && device_index != 0) {
std::cerr << "[WARNING]: Only one device is available for MPS runs"
<< std::endl;
}
return torch::Device(torch::kMPS);
case torch_kXPU:
if (device_index != -1) {
std::cerr << "[WARNING]: device index unused for XPU runs"
<< std::endl;
}
return torch::Device(torch::kXPU);
default:
std::cerr << "[WARNING]: unknown device type, setting to torch_kCPU"
<< std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/ctorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef enum {
} torch_data_t;

// Device types
typedef enum { torch_kCPU, torch_kCUDA } torch_device_t;
typedef enum { torch_kCPU, torch_kCUDA, torch_kMPS, torch_kXPU } torch_device_t;


// =====================================================================================
Expand Down
2 changes: 2 additions & 0 deletions src/ftorch.f90
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ module ftorch
enum, bind(c)
enumerator :: torch_kCPU = 0
enumerator :: torch_kCUDA = 1
enumerator :: torch_kMPS = 2
enumerator :: torch_kXPU = 3
end enum

!> Interface for directing `torch_tensor_from_array` to possible input types and ranks
Expand Down
2 changes: 2 additions & 0 deletions src/ftorch.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ module ftorch
enum, bind(c)
enumerator :: torch_kCPU = 0
enumerator :: torch_kCUDA = 1
enumerator :: torch_kMPS = 2
enumerator :: torch_kXPU = 3
end enum

!> Interface for directing `torch_tensor_from_array` to possible input types and ranks
Expand Down
Loading