-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[DynamicCompilation] Add _AnyTensorHandle and Swift-C round trip entry points #19529
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
Changes from all commits
e3d7cea
cf011c7
cab4cf1
44dc0c7
bf202f0
79d65ae
f1617de
e1d9812
6d9a6dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// RUN: %target-run-simple-swift | ||
// REQUIRES: executable_test | ||
// REQUIRES: swift_test_mode_optimize | ||
|
||
import CTensorFlow | ||
import TensorFlow | ||
import TensorFlowUnittest | ||
import StdlibUnittest | ||
|
||
var RuntimeEntryPointTests = TestSuite("RuntimeEntryPoint") | ||
|
||
RuntimeEntryPointTests.testCPUOrGPU("RoundTrip_CTensorHandle_AnyTensorHandle") { | ||
let zero: TensorHandle<Float> = | ||
#tfop("Const", dtype: Float.self, value$tensor: 0.0) | ||
var cHandle = _TFCGetCTensorHandleFromSwift(zero as _AnyTensorHandle) | ||
let status = TF_NewStatus() | ||
// We must do a copy, i.e. a retain on the tensor handle, to make sure it won't | ||
// get double-free'd when both `zero` and `anyHandle` below go out of scope. | ||
cHandle = TFE_TensorHandleCopySharingTensor(cHandle, status) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm this suggests using In IRgen, for a given tensor handle Can we call TFE_TensorHandleCopySharingTensor() within There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will the corresponding TF call emitted by IRGen consume the retain count? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we discussed in person, making This test case is irrelevant because it's making a new |
||
expectEqual(TF_GetCode(status), TF_OK) | ||
TF_DeleteStatus(status) | ||
let anyHandle = _TFCCreateTensorHandleFromC(cHandle) | ||
let tensor = Tensor(handle: anyHandle as! TensorHandle<Float>) | ||
print(tensor) | ||
expectTrue(tensor == Tensor(0.0)) | ||
} | ||
|
||
runAllTests() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TensorHandle -> _AnyTensorHandle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I'm going to move initializers back into
TensorHandle<T>
since only that would be correct, and_AnyTensorHandle
is just a type-erased class for easier IRGen. So it's always a TensorHandle.