Skip to content

Commit c839b9e

Browse files
jorgep31415facebook-github-bot
authored andcommitted
Move Tensor.* to namespace api (#4124)
Summary: Pull Request resolved: #4124 Then, update usage via ``` find . -type f -exec sed -i 's/vTensor/api::vTensor/g' {} + find . -type f -exec sed -i 's/api::vTensorPtr/vTensorPtr/g' {} + ``` ghstack-source-id: 232367491 exported-using-ghexport bypass-github-export-checks bypass-github-pytorch-ci-checks bypass-github-executorch-ci-checks Reviewed By: SS-JIA Differential Revision: D59281541 fbshipit-source-id: 2258b9d2da22a966cf5b4c297ba4e5eb47123e0f
1 parent 0490402 commit c839b9e

29 files changed

+343
-326
lines changed

backends/vulkan/runtime/api/Tensor.cpp

Lines changed: 93 additions & 94 deletions
Large diffs are not rendered by default.

backends/vulkan/runtime/api/Tensor.h

Lines changed: 52 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <executorch/backends/vulkan/runtime/api/Types.h>
1616

1717
namespace vkcompute {
18+
namespace api {
1819

1920
/*
2021
* Given the sizes of a tensor and the GPU memory layout, calculate the strides
@@ -29,7 +30,7 @@ namespace vkcompute {
2930
*/
3031
std::vector<int64_t> calculate_strides(
3132
const std::vector<int64_t>& sizes,
32-
const api::GPUMemoryLayout memory_layout,
33+
const GPUMemoryLayout memory_layout,
3334
const bool texel_strides = true);
3435

3536
/*
@@ -48,27 +49,24 @@ std::vector<int64_t> calculate_strides(
4849
*/
4950
std::vector<int64_t> calculate_padded_sizes(
5051
const std::vector<int64_t>& sizes,
51-
const api::GPUMemoryLayout memory_layout);
52+
const GPUMemoryLayout memory_layout);
5253

5354
/*
5455
* Given the padded sizes of a tensor and the GPU memory layout, calculate the
5556
* 3D image extents required to store the tensor data as an image texture.
5657
*/
5758
utils::uvec3 calculate_image_extents(
5859
const std::vector<int64_t>& padded_sizes,
59-
const api::GPUMemoryLayout memory_layout);
60+
const GPUMemoryLayout memory_layout);
6061

6162
struct LastAccess {
62-
api::PipelineStageFlags stage;
63-
api::MemoryAccessFlags access;
63+
PipelineStageFlags stage;
64+
MemoryAccessFlags access;
6465

6566
LastAccess()
66-
: stage{api::PipelineStage::NO_STAGE},
67-
access{api::MemoryAccessType::NONE} {}
67+
: stage{PipelineStage::NO_STAGE}, access{MemoryAccessType::NONE} {}
6868

69-
LastAccess(
70-
api::PipelineStageFlags stage_flags,
71-
api::MemoryAccessFlags access_flags)
69+
LastAccess(PipelineStageFlags stage_flags, MemoryAccessFlags access_flags)
7270
: stage{stage_flags}, access{access_flags} {}
7371
};
7472

@@ -78,11 +76,11 @@ class vTensorStorage final {
7876
vTensorStorage() = default;
7977

8078
vTensorStorage(
81-
api::Context* context,
82-
const api::StorageType storage_type,
83-
const api::GPUMemoryLayout gpu_memory_layout,
79+
Context* context,
80+
const StorageType storage_type,
81+
const GPUMemoryLayout gpu_memory_layout,
8482
const std::vector<int64_t>& sizes,
85-
const api::ScalarType dtype,
83+
const ScalarType dtype,
8684
const bool allocate_memory = true);
8785

8886
vTensorStorage(const vTensorStorage& other) = delete;
@@ -97,17 +95,17 @@ class vTensorStorage final {
9795

9896
private:
9997
// Context
100-
api::Context* context_{};
98+
Context* context_{};
10199

102-
api::StorageType storage_type_;
100+
StorageType storage_type_;
103101

104102
// Resource sizings
105103
utils::uvec3 image_extents_{};
106104
int64_t buffer_length_{};
107105

108106
// GPU Storage
109-
mutable api::VulkanImage image_;
110-
mutable api::VulkanBuffer buffer_;
107+
mutable VulkanImage image_;
108+
mutable VulkanBuffer buffer_;
111109

112110
// Last Access - used to insert memory barriers
113111
LastAccess last_access_;
@@ -118,9 +116,9 @@ class vTensorStorage final {
118116

119117
// Memory barrier insertion
120118
void transition(
121-
api::PipelineBarrier&,
122-
const api::PipelineStageFlags,
123-
const api::MemoryAccessFlags);
119+
PipelineBarrier&,
120+
const PipelineStageFlags,
121+
const MemoryAccessFlags);
124122

125123
// Validation
126124
void verify() const;
@@ -132,8 +130,8 @@ class vTensorStorage final {
132130

133131
void discard_and_reallocate(
134132
const std::vector<int64_t>& padded_sizes,
135-
const api::GPUMemoryLayout gpu_memory_layout,
136-
const api::ScalarType dtype);
133+
const GPUMemoryLayout gpu_memory_layout,
134+
const ScalarType dtype);
137135
};
138136

139137
class vTensor final {
@@ -146,11 +144,11 @@ class vTensor final {
146144

147145
public:
148146
explicit vTensor(
149-
api::Context* context,
147+
Context* context,
150148
const std::vector<int64_t>& sizes,
151-
const api::ScalarType dtype,
152-
const api::StorageType storage_type = api::kTexture3D,
153-
const api::GPUMemoryLayout memory_layout = api::kChannelsPacked,
149+
const ScalarType dtype,
150+
const StorageType storage_type = kTexture3D,
151+
const GPUMemoryLayout memory_layout = kChannelsPacked,
154152
const bool allocate_memory = true);
155153

156154
vTensor(const vTensor& other) = delete;
@@ -160,8 +158,8 @@ class vTensor final {
160158
vTensor& operator=(vTensor&& other) = default;
161159

162160
private:
163-
api::ScalarType dtype_;
164-
api::GPUMemoryLayout memory_layout_;
161+
ScalarType dtype_;
162+
GPUMemoryLayout memory_layout_;
165163

166164
// sizes of the tensor in NCHW dimension order
167165
std::vector<int64_t> sizes_;
@@ -181,10 +179,10 @@ class vTensor final {
181179
* Refer to the comments for the corresponding *_ubo() functions for more
182180
* context about the data contained in each buffer.
183181
*/
184-
api::ParamsBuffer sizes_uniform_;
185-
api::ParamsBuffer texture_limits_uniform_;
186-
api::ParamsBuffer texel_strides_uniform_;
187-
api::ParamsBuffer ntexels_uniform_;
182+
ParamsBuffer sizes_uniform_;
183+
ParamsBuffer texture_limits_uniform_;
184+
ParamsBuffer texel_strides_uniform_;
185+
ParamsBuffer ntexels_uniform_;
188186

189187
vTensorStorage storage_;
190188

@@ -193,56 +191,48 @@ class vTensor final {
193191
Texture Access
194192
*/
195193

196-
inline api::VulkanImage& image() const& {
194+
inline VulkanImage& image() const& {
197195
return storage_.image_;
198196
}
199197

200-
api::VulkanImage& image(
201-
api::PipelineBarrier&,
202-
const api::PipelineStageFlags) &;
198+
VulkanImage& image(PipelineBarrier&, const PipelineStageFlags) &;
203199

204-
api::VulkanImage& image(
205-
api::PipelineBarrier&,
206-
const api::PipelineStageFlags,
207-
const api::MemoryAccessFlags) &;
200+
VulkanImage&
201+
image(PipelineBarrier&, const PipelineStageFlags, const MemoryAccessFlags) &;
208202

209-
inline api::VulkanBuffer& buffer() const& {
203+
inline VulkanBuffer& buffer() const& {
210204
return storage_.buffer_;
211205
}
212206

213-
api::VulkanBuffer& buffer(
214-
api::PipelineBarrier&,
215-
const api::PipelineStageFlags) &;
207+
VulkanBuffer& buffer(PipelineBarrier&, const PipelineStageFlags) &;
216208

217-
api::VulkanBuffer& buffer(
218-
api::PipelineBarrier&,
219-
const api::PipelineStageFlags,
220-
const api::MemoryAccessFlags) &;
209+
VulkanBuffer&
210+
buffer(PipelineBarrier&, const PipelineStageFlags, const MemoryAccessFlags) &;
221211

222212
/*
223213
Metadata
224214
*/
225215

226-
inline api::StorageType storage_type() const {
216+
inline StorageType storage_type() const {
227217
return storage_.storage_type_;
228218
}
229219

230220
inline bool has_buffer_storage() const {
231-
return storage_.storage_type_ == api::kBuffer;
221+
return storage_.storage_type_ == kBuffer;
232222
}
233223

234224
inline const utils::uvec3& image_extents() const {
235225
return storage_.image_extents_;
236226
}
237227

238228
/*
239-
* Extract an `api::ScalarType` from the TensorOptions member
229+
* Extract an `ScalarType` from the TensorOptions member
240230
*/
241-
inline api::ScalarType dtype() const {
231+
inline ScalarType dtype() const {
242232
return dtype_;
243233
}
244234

245-
inline api::GPUMemoryLayout gpu_memory_layout() const {
235+
inline GPUMemoryLayout gpu_memory_layout() const {
246236
return memory_layout_;
247237
}
248238

@@ -267,7 +257,7 @@ class vTensor final {
267257
* Note that dimensions that are not present in the tensor's sizes are set to
268258
* a size of 1.
269259
*/
270-
const api::BufferBindInfo sizes_ubo();
260+
const BufferBindInfo sizes_ubo();
271261

272262
/*
273263
* Returns a GPU buffer containing the virtual image extents of the tensor.
@@ -278,18 +268,18 @@ class vTensor final {
278268
*
279269
* This buffer should only be used to
280270
*/
281-
const api::BufferBindInfo texture_limits_ubo();
271+
const BufferBindInfo texture_limits_ubo();
282272

283273
/*
284274
* Returns the strides of the texel buffer used to store the tensor, as
285275
* calculated by calculate_strides().
286276
*/
287-
const api::BufferBindInfo texel_strides_ubo();
277+
const BufferBindInfo texel_strides_ubo();
288278

289279
/*
290280
* Returns the number of texels in the texel buffer used to store the tensor.
291281
*/
292-
const api::BufferBindInfo ntexels_ubo();
282+
const BufferBindInfo ntexels_ubo();
293283

294284
inline const utils::ivec3 texture_limits() const {
295285
return texture_limits_.limits;
@@ -300,7 +290,7 @@ class vTensor final {
300290
}
301291

302292
inline size_t nbytes() const {
303-
return api::element_size(dtype()) * numel();
293+
return element_size(dtype()) * numel();
304294
}
305295

306296
/*
@@ -322,7 +312,7 @@ class vTensor final {
322312
* Return nbytes but based on padded_sizes_ instead of sizes_
323313
*/
324314
inline VkDeviceSize gpu_nbytes() const {
325-
return api::element_size(dtype()) * gpu_numel();
315+
return element_size(dtype()) * gpu_numel();
326316
}
327317

328318
/*
@@ -338,7 +328,7 @@ class vTensor final {
338328
/*
339329
* Binds the underlying resource to the given memory allocation
340330
*/
341-
void bind_allocation(const api::Allocation& allocation);
331+
void bind_allocation(const Allocation& allocation);
342332

343333
private:
344334
/*
@@ -362,4 +352,5 @@ class vTensor final {
362352
void virtual_resize(const std::vector<int64_t>& new_sizes);
363353
};
364354

355+
} // namespace api
365356
} // namespace vkcompute

backends/vulkan/runtime/graph/ComputeGraph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace vkcompute {
3636
graph_->values_in_use_--; \
3737
}
3838

39-
VALUE_PTR_CLASS_IMPL(vTensorPtr, vTensor, Tensor)
39+
VALUE_PTR_CLASS_IMPL(vTensorPtr, api::vTensor, Tensor)
4040
VALUE_PTR_CLASS_IMPL(TensorRefPtr, TensorRef, TensorRef)
4141
VALUE_PTR_CLASS_IMPL(StagingPtr, api::StorageBuffer, Staging)
4242
VALUE_PTR_CLASS_IMPL(IntListPtr, std::vector<int64_t>, IntList)
@@ -151,7 +151,7 @@ ValueRef ComputeGraph::add_tensor(
151151

152152
ValueRef idx(static_cast<int>(values_.size()));
153153
check_no_active_value_ptrs();
154-
values_.emplace_back(vTensor(
154+
values_.emplace_back(api::vTensor(
155155
context(), sizes, dtype, storage_type, memory_layout, allocate_memory));
156156

157157
if (!allocate_memory) {

0 commit comments

Comments
 (0)