Skip to content

Commit 28beeff

Browse files
authored
Clean up devtools/etdump
Differential Revision: D62394222 Pull Request resolved: #5180
1 parent b23ee01 commit 28beeff

File tree

7 files changed

+364
-343
lines changed

7 files changed

+364
-343
lines changed

devtools/etdump/emitter.cpp

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,25 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
#include <stdio.h>
9+
#include <executorch/devtools/etdump/emitter.h>
10+
1011
#include <cstdint>
12+
#include <cstring>
13+
14+
#include <executorch/devtools/etdump/etdump_flatcc.h>
15+
#include <executorch/runtime/platform/assert.h>
16+
17+
#include <flatcc/flatcc_builder.h>
1118

12-
#include "executorch/devtools/etdump/emitter.h"
13-
#include "executorch/runtime/platform/assert.h"
19+
using executorch::etdump::internal::ETDumpStaticAllocator;
1420

15-
namespace torch {
16-
namespace executor {
21+
namespace executorch {
22+
namespace etdump {
23+
namespace internal {
1724

18-
static int _allocator_fn(
25+
namespace {
26+
27+
int allocator_fn(
1928
void* alloc_context,
2029
flatcc_iovec_t* b,
2130
size_t request,
@@ -24,8 +33,8 @@ static int _allocator_fn(
2433
void* p;
2534
size_t n;
2635

27-
struct etdump_static_allocator* state =
28-
(struct etdump_static_allocator*)alloc_context;
36+
ETDumpStaticAllocator* state =
37+
reinterpret_cast<ETDumpStaticAllocator*>(alloc_context);
2938

3039
// This allocator doesn't support freeing memory.
3140
if (request == 0) {
@@ -113,14 +122,14 @@ static int _allocator_fn(
113122

114123
// This emitter implementation emits to a fixed size buffer and will fail if it
115124
// runs out of room on either end.
116-
static int _emitter_fn(
125+
int emitter_fn(
117126
void* emit_context,
118127
const flatcc_iovec_t* iov,
119128
int iov_count,
120129
flatbuffers_soffset_t offset,
121130
size_t len) {
122-
struct etdump_static_allocator* E =
123-
(struct etdump_static_allocator*)emit_context;
131+
ETDumpStaticAllocator* E =
132+
reinterpret_cast<ETDumpStaticAllocator*>(emit_context);
124133
uint8_t* p;
125134

126135
if (offset < 0) {
@@ -144,40 +153,15 @@ static int _emitter_fn(
144153
return 0;
145154
}
146155

147-
/*******************************************************************************
148-
* Public Functions
149-
******************************************************************************/
150-
151-
int etdump_static_allocator_builder_init(
152-
flatcc_builder_t* builder,
153-
struct etdump_static_allocator* alloc) {
154-
ET_CHECK(builder != nullptr);
155-
ET_CHECK(alloc != nullptr);
156-
157-
// Ensure data size is multiple of 32 (minimum allocation size).
158-
ET_CHECK((alloc->data_size & 0x1F) == 0);
159-
// Ensure out_size is divisable by 2 to ensure front/back sizes are equal for
160-
// emitter..
161-
ET_CHECK((alloc->out_size & 0x1) == 0);
162-
163-
return flatcc_builder_custom_init(
164-
builder, _emitter_fn, alloc, _allocator_fn, alloc);
165-
}
166-
167-
void etdump_static_allocator_reset(struct etdump_static_allocator* alloc) {
168-
ET_CHECK(alloc != nullptr);
169-
alloc->allocated = 0;
170-
size_t n = alloc->out_size / 2;
171-
alloc->front_cursor = &alloc->data[alloc->data_size + n];
172-
alloc->front_left = n;
173-
}
156+
} // namespace
174157

175-
int et_flatcc_custom_init(
158+
int etdump_flatcc_custom_init(
176159
flatcc_builder_t* builder,
177-
struct etdump_static_allocator* alloc) {
160+
struct ETDumpStaticAllocator* alloc) {
178161
return flatcc_builder_custom_init(
179-
builder, _emitter_fn, alloc, _allocator_fn, alloc);
162+
builder, emitter_fn, alloc, allocator_fn, alloc);
180163
}
181164

182-
} // namespace executor
183-
} // namespace torch
165+
} // namespace internal
166+
} // namespace etdump
167+
} // namespace executorch

devtools/etdump/emitter.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,23 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
#include <stdint.h>
10-
#include <stdlib.h>
9+
#pragma once
1110

12-
#include <executorch/devtools/etdump/etdump_flatcc.h>
13-
#include <flatcc/flatcc_builder.h>
11+
#include <cstdint>
12+
#include <cstdlib>
1413

15-
#pragma once
14+
#include <executorch/devtools/etdump/etdump_flatcc.h>
1615

17-
namespace torch {
18-
namespace executor {
16+
typedef struct flatcc_builder flatcc_builder_t;
1917

20-
int et_flatcc_custom_init(
21-
flatcc_builder_t* builder,
22-
struct etdump_static_allocator* alloc);
18+
namespace executorch {
19+
namespace etdump {
20+
namespace internal {
2321

24-
int etdump_static_allocator_builder_init(
22+
int etdump_flatcc_custom_init(
2523
flatcc_builder_t* builder,
26-
struct etdump_static_allocator* alloc);
27-
28-
void etdump_static_allocator_reset(struct etdump_static_allocator* alloc);
24+
internal::ETDumpStaticAllocator* alloc);
2925

30-
} // namespace executor
31-
} // namespace torch
26+
} // namespace internal
27+
} // namespace etdump
28+
} // namespace executorch

0 commit comments

Comments
 (0)