Skip to content

Commit 5af97e3

Browse files
committed
Update on "[devtool] introduce datasink class to etdump"
this diff introduce datasink class, the class for managing the customized debug data storage pipeline. Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0 Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/) [ghstack-poisoned]
2 parents b06769e + 7086686 commit 5af97e3

File tree

3 files changed

+14
-25
lines changed

3 files changed

+14
-25
lines changed

devtools/etdump/buffer_data_sink.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ Result<size_t> BufferDataSink::write(const void* ptr, size_t length) {
3737
return (size_t)(offset_ptr - debug_buffer_.data());
3838
}
3939

40-
Result<size_t> BufferDataSink::write_tensor(
41-
const executorch::aten::Tensor& tensor) {
42-
return write(tensor.const_data_ptr(), tensor.nbytes());
43-
}
44-
4540
Result<size_t> BufferDataSink::get_storage_size() const {
4641
return debug_buffer_.size();
4742
}

devtools/etdump/buffer_data_sink.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,24 @@ class BufferDataSink : public DataSinkBase {
3535

3636
BufferDataSink(const BufferDataSink&) = delete;
3737
BufferDataSink& operator=(const BufferDataSink&) = delete;
38+
BufferDataSink(BufferDataSink&&) = default;
39+
BufferDataSink& operator=(BufferDataSink&&) = default;
3840

3941
/**
4042
* Write data into the debug buffer and return the offset of the starting
4143
* location of the data within the buffer.
4244
*
4345
* @param[in] ptr A pointer to the data to be written into the storage.
44-
* @param[in] length The size of the data in bytes.
46+
* @param[in] size The size of the data in bytes.
4547
* @return A Result object containing either:
4648
* - The offset of the starting location of the data within the
4749
* debug buffer, or
4850
* - An error code indicating the failure reason, if any issue
4951
* occurs during the write process.
5052
*/
51-
::executorch::runtime::Result<size_t> write(const void* ptr, size_t length)
53+
::executorch::runtime::Result<size_t> write(const void* ptr, size_t size)
5254
override;
5355

54-
/**
55-
* Write tensor into the debug buffer and return the offset of the starting
56-
* location of the data within the buffer.
57-
* @param[in] tensor A reference to the tensor whose data is to be written.
58-
* @return A Result object containing either:
59-
* - The offset of the starting location of the data within the
60-
* debug buffer, or
61-
* - An error code indicating the failure reason, if any issue
62-
* occurs during the write process.
63-
*/
64-
::executorch::runtime::Result<size_t> write_tensor(
65-
const executorch::aten::Tensor& tensor);
66-
6756
/**
6857
* Retrieves the total size of the buffer.
6958
*

devtools/etdump/tests/buffer_data_sink_test.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ TEST_F(BufferDataSinkTest, WriteOneTensorAndCheckData) {
5454
TensorFactory<ScalarType::Float> tf;
5555
Tensor tensor = tf.make({1, 4}, {1.0, 2.0, 3.0, 4.0});
5656

57-
Result<size_t> ret = data_sink_->write_tensor(tensor);
57+
Result<size_t> ret =
58+
data_sink_->write(tensor.const_data_ptr(), tensor.nbytes());
5859
ASSERT_EQ(ret.error(), Error::Ok);
5960

6061
size_t offset = ret.get();
@@ -75,7 +76,8 @@ TEST_F(BufferDataSinkTest, WriteMultiTensorsAndCheckData) {
7576
tf.make({1, 4}, {1.0, 2.0, 3.0, 4.0}),
7677
tf.make({1, 4}, {5.0, 6.0, 7.0, 8.0})};
7778
for (const auto& tensor : tensors) {
78-
Result<size_t> ret = data_sink_->write_tensor(tensor);
79+
Result<size_t> ret =
80+
data_sink_->write(tensor.const_data_ptr(), tensor.nbytes());
7981
ASSERT_EQ(ret.error(), Error::Ok);
8082

8183
size_t offset = ret.get();
@@ -92,7 +94,8 @@ TEST_F(BufferDataSinkTest, WriteMultiTensorsAndCheckData) {
9294
TEST_F(BufferDataSinkTest, PointerAlignmentCheck) {
9395
TensorFactory<ScalarType::Float> tf;
9496
Tensor tensor = tf.make({1, 4}, {1.0, 2.0, 3.0, 4.0});
95-
Result<size_t> ret = data_sink_->write_tensor(tensor);
97+
Result<size_t> ret =
98+
data_sink_->write(tensor.const_data_ptr(), tensor.nbytes());
9699
ASSERT_EQ(ret.error(), Error::Ok);
97100

98101
size_t offset = ret.get();
@@ -108,11 +111,13 @@ TEST_F(BufferDataSinkTest, WriteUntilOverflow) {
108111

109112
// Write tensors until we run out of space
110113
for (size_t i = 0; i < 2; i++) {
111-
Result<size_t> ret = data_sink_->write_tensor(tensor);
114+
Result<size_t> ret =
115+
data_sink_->write(tensor.const_data_ptr(), tensor.nbytes());
112116
ASSERT_EQ(ret.error(), Error::Ok);
113117
}
114118

115119
// Attempting to write another tensor should raise an error
116-
Result<size_t> ret = data_sink_->write_tensor(tensor);
120+
Result<size_t> ret =
121+
data_sink_->write(tensor.const_data_ptr(), tensor.nbytes());
117122
ASSERT_EQ(ret.error(), Error::AccessFailed);
118123
}

0 commit comments

Comments
 (0)