forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DLPack support for XPU backend by mapping to kDLOneAPI in DLPack (p…
…ytorch#82867) ## Motivation The DLPack device type kDLOneAPI stands for the Unified Shared Memory allocated on a oneAPI device. The corresponding Pytorch backend type is XPU. Support to export/import the Pytorch XPU tensor as a DLPack tensor of kDLOneAPI device. ## Solution 1. Update the DLPack protocol to v0.7. 2. Add the XPU hooks to map the Aten device and DLPack device with the address value and device information. Pull Request resolved: pytorch#82867 Approved by: https://github.com/kit1980
- Loading branch information
1 parent
bfebf25
commit de0e030
Showing
11 changed files
with
208 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <ATen/detail/XPUHooksInterface.h> | ||
|
||
#include <c10/util/CallOnce.h> | ||
|
||
#include <memory> | ||
#include <mutex> | ||
|
||
namespace at { | ||
namespace detail { | ||
|
||
static XPUHooksInterface *xpu_hooks = nullptr; | ||
|
||
const XPUHooksInterface &getXPUHooks() { | ||
static c10::once_flag once; | ||
c10::call_once(once, [] { | ||
xpu_hooks = | ||
XPUHooksRegistry()->Create("XPUHooks", XPUHooksArgs{}).release(); | ||
if (!xpu_hooks) { | ||
xpu_hooks = new XPUHooksInterface(); | ||
} | ||
}); | ||
return *xpu_hooks; | ||
} | ||
} // namespace detail | ||
|
||
C10_DEFINE_REGISTRY(XPUHooksRegistry, XPUHooksInterface, XPUHooksArgs) | ||
|
||
} // namespace at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#pragma once | ||
|
||
#include <ATen/dlpack.h> | ||
#include <c10/core/Device.h> | ||
#include <c10/util/Exception.h> | ||
|
||
#include <c10/util/Registry.h> | ||
|
||
#include <cstddef> | ||
#include <functional> | ||
#include <memory> | ||
|
||
namespace at { | ||
class Context; | ||
} | ||
|
||
namespace at { | ||
|
||
constexpr const char* XPU_HELP = | ||
"The XPU backend requires Intel Extension for Pytorch;" | ||
"this error has occurred because you are trying " | ||
"to use some XPU's functionality, but the Intel Extension for Pytorch has not been " | ||
"loaded for some reason. The Intel Extension for Pytorch MUST " | ||
"be loaded, EVEN IF you don't directly use any symbols from that!"; | ||
|
||
struct TORCH_API XPUHooksInterface { | ||
virtual ~XPUHooksInterface() {} | ||
|
||
virtual void initXPU() const { | ||
TORCH_CHECK( | ||
false, | ||
"Cannot initialize XPU without Intel Extension for Pytorch.", | ||
XPU_HELP); | ||
} | ||
|
||
virtual bool hasXPU() const { | ||
return false; | ||
} | ||
|
||
virtual std::string showConfig() const { | ||
TORCH_CHECK( | ||
false, | ||
"Cannot query detailed XPU version without Intel Extension for Pytorch. ", | ||
XPU_HELP); | ||
} | ||
|
||
virtual Device getATenDeviceFromDLPackDevice( | ||
const DLDevice& dl_device, | ||
void* data) const { | ||
TORCH_CHECK( | ||
false, | ||
"Cannot get XPU device without Intel Extension for Pytorch. ", | ||
XPU_HELP); | ||
}; | ||
|
||
virtual DLDevice getDLPackDeviceFromATenDevice( | ||
const Device& aten_device, | ||
void* data) const { | ||
TORCH_CHECK( | ||
false, | ||
"Cannot get XPU DL device without Intel Extension for Pytorch. ", | ||
XPU_HELP); | ||
}; | ||
}; | ||
|
||
struct TORCH_API XPUHooksArgs {}; | ||
|
||
C10_DECLARE_REGISTRY(XPUHooksRegistry, XPUHooksInterface, XPUHooksArgs); | ||
#define REGISTER_XPU_HOOKS(clsname) \ | ||
C10_REGISTER_CLASS(XPUHooksRegistry, clsname, clsname) | ||
|
||
namespace detail { | ||
TORCH_API const XPUHooksInterface& getXPUHooks(); | ||
} // namespace detail | ||
} // namespace at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.