forked from snuspl/nimble
-
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 XLA / TPU device type, backend type and type id (#16763)
Summary: Pull Request resolved: pytorch/pytorch#16763 Replicate the easy bits in pytorch/pytorch#15153 with TPU / XLA instead of MSNPU. Also don't initialize the storage for XLA tensors for now. Pull Request resolved: pytorch/pytorch#16585 Reviewed By: ezyang Differential Revision: D13912118 Pulled By: gchanan fbshipit-source-id: 4889177e2478768fb281ed075b71146d1d850bd9
- Loading branch information
1 parent
6efa40e
commit 9811a42
Showing
13 changed files
with
72 additions
and
7 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,34 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <ATen/ATen.h> | ||
|
||
using namespace at; | ||
|
||
void XLAFree(void *ptr) { | ||
free(ptr); | ||
} | ||
|
||
void* XLAMalloc(ptrdiff_t size) { | ||
return malloc(size); | ||
} | ||
|
||
struct XLAAllocator final : public at::Allocator { | ||
at::DataPtr allocate(size_t size) const override { | ||
auto* ptr = XLAMalloc(size); | ||
return {ptr, ptr, &XLAFree, at::DeviceType::XLA}; | ||
} | ||
at::DeleterFnPtr raw_deleter() const override { | ||
return &XLAFree; | ||
} | ||
}; | ||
|
||
TEST(XlaTensorTest, TestNoStorage) { | ||
XLAAllocator allocator; | ||
auto storage = Storage(caffe2::TypeMeta::Make<float>(), 0, &allocator, true); | ||
auto tensor_impl = c10::make_intrusive<TensorImpl, UndefinedTensorImpl>( | ||
std::move(storage), | ||
XLATensorId(), | ||
/*is_variable=*/false); | ||
at::Tensor t(std::move(tensor_impl)); | ||
ASSERT_TRUE(t.device() == DeviceType::XLA); | ||
} |
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
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
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