-
Notifications
You must be signed in to change notification settings - Fork 615
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
Remove possibility of access to contiguous TL buffer #3373
Conversation
dali/pipeline/data/buffer.h
Outdated
@@ -86,71 +86,6 @@ class DLL_PUBLIC Buffer { | |||
inline Buffer() = default; | |||
virtual ~Buffer() = default; | |||
|
|||
/** |
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.
This was just moved from public:
to protected:
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.
I don't like it. The Buffer
class is really quite useless after this change. How about making the inheritance of TensorList from Buffer protected (or even private) instead?
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.
useless -> redundant ?
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.
Switched to private inheritance.
dali/pipeline/data/tensor.h
Outdated
|
||
/** | ||
* @brief Returns a typed pointer to the underlying storage. If the | ||
* buffer has not been allocated because it does not yet have a type, |
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.
* buffer has not been allocated because it does not yet have a type, | |
* tensor has not been allocated because it does not yet have a type, |
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.
As this is the Tensor API I would stick to using tensor
in the docs.
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.
I just copied the old Doxygen verbatim from tensor, I can adjust if you want.
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.
I would appreciate that.
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.
All removed, will resolve stale comments.
dali/pipeline/data/tensor.h
Outdated
* | ||
* If the buffer already has a valid type, and the calling type does | ||
* not match, the type of the buffer is reset and the underlying | ||
* storage is re-allocated if the buffer does not currently own |
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.
* storage is re-allocated if the buffer does not currently own | |
* storage is re-allocated if the tensor does not currently own |
CI MESSAGE: [3049105]: BUILD STARTED |
dali/pipeline/data/tensor_list.h
Outdated
|
||
/** | ||
* @brief Return an un-typed pointer to the underlying storage. | ||
* Buffer must be either empty or have a valid type and be contiguous. |
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.
* Buffer must be either empty or have a valid type and be contiguous. | |
* The memory must be either empty or have a valid type and be contiguous. |
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.
done
dali/pipeline/data/tensor_list.h
Outdated
|
||
/** | ||
* @brief Return an un-typed const pointer to the underlying storage. | ||
* Buffer must be either empty or have a valid type and be contiguous. |
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.
* Buffer must be either empty or have a valid type and be contiguous. | |
* The memory must be either empty or have a valid type and be contiguous. |
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.
done
|
||
// Check the internals | ||
ASSERT_NE(tensor_list->template mutable_data<float>(), nullptr); | ||
ASSERT_TRUE(tensor_list->has_data()); |
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.
Shouldn't you specialize has_data
to the TensorList now (as it is implemented in the buffer)?
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.
I maybe can do something, but I think it needs to wait for the proper changes.
|
||
// Check the internals | ||
ASSERT_EQ(tensor_list.ntensor(), shape.size()); | ||
for (size_t i = 0; i < tensor_list.ntensor(); ++i) { | ||
// ASSERT_EQ(ptrs[i], tensor_list.raw_tensor(i)); |
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.
?
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.
done
ASSERT_EQ(tensor_list.tensor_shape(i), shape[i]); | ||
ASSERT_EQ(tensor_list.tensor_offset(i), offsets[i]); | ||
} | ||
|
||
// No memory allocation should have occured | ||
ASSERT_EQ(ptr, tensor_list.raw_data()); |
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.
Maybe we can save ptrs to each tensor and then check if no reallocation has happened.
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.
I cannot check if no reallocation happen this way, as it will match only for the first pointer. I can add the unsafe call.
DeviceGuard d(src.device_id()); | ||
const auto &type_info = src.type_info(); | ||
|
||
// TODO(klecki): Add a proper test for non-contiguous access when we can have non-contiguous |
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.
Do think we will have such case?
I imagine that DALI still should return raw outputs as continuous tensors so we can wrap them into CuPy/NumPy or DLPack directly.
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.
I just wrote it for the sake of TODO for the next PR mostly, I guess we won't be returning non-contiguous stuff soon, but either way I will add an error here or test this code-path and error out somewhere else.
const auto &src_shape = src.shape(); | ||
auto *dst_buf = static_cast<uint8_t *>(dst); SmallVector<void *, 256> to; | ||
SmallVector<const void *, 256> from; | ||
SmallVector<int64_t, 256> sizes; | ||
int num_samples = src_shape.num_samples(); | ||
sizes.reserve(num_samples); | ||
to.reserve(num_samples); | ||
from.reserve(num_samples); | ||
for (int i = 0; i < num_samples; i++) { | ||
sizes.push_back(src_shape.tensor_size(i)); | ||
to.push_back(dst_buf); | ||
dst_buf += sizes[i] * type_info.size(); | ||
from.push_back(src.raw_tensor(i)); | ||
} | ||
|
||
type_info.template Copy<DstBackend, SrcBackend>(to.data(), from.data(), sizes.data(), | ||
num_samples, stream, use_copy_kernel); | ||
} |
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.
const auto &src_shape = src.shape(); | |
auto *dst_buf = static_cast<uint8_t *>(dst); SmallVector<void *, 256> to; | |
SmallVector<const void *, 256> from; | |
SmallVector<int64_t, 256> sizes; | |
int num_samples = src_shape.num_samples(); | |
sizes.reserve(num_samples); | |
to.reserve(num_samples); | |
from.reserve(num_samples); | |
for (int i = 0; i < num_samples; i++) { | |
sizes.push_back(src_shape.tensor_size(i)); | |
to.push_back(dst_buf); | |
dst_buf += sizes[i] * type_info.size(); | |
from.push_back(src.raw_tensor(i)); | |
} | |
type_info.template Copy<DstBackend, SrcBackend>(to.data(), from.data(), sizes.data(), | |
num_samples, stream, use_copy_kernel); | |
} | |
const auto &src_shape = src.shape(); | |
SmallVector<const void *, 256> from; | |
SmallVector<int64_t, 256> sizes; | |
int num_samples = src_shape.num_samples(); | |
sizes.reserve(num_samples); | |
to.reserve(num_samples); | |
from.reserve(num_samples); | |
for (int i = 0; i < num_samples; i++) { | |
sizes.push_back(src_shape.tensor_size(i)); | |
from.push_back(src.raw_tensor(i)); | |
} | |
type_info.template Copy<DstBackend, SrcBackend>(dst, from.data(), sizes.data(), | |
num_samples, stream, use_copy_kernel); | |
} |
As we have:
template <typename DstBackend, typename SrcBackend>
void TypeInfo::Copy(void *dst, const void** srcs, const Index* sizes, int n,
cudaStream_t stream, bool use_copy_kernel) const {
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.
Done
CI MESSAGE: [3049105]: BUILD PASSED |
!build |
CI MESSAGE: [3063967]: BUILD STARTED |
"Can only wait on user streams"); | ||
DeviceGuard g(dev); | ||
CUDA_CALL(cudaStreamSynchronize(streams_[dev])); | ||
DLL_PUBLIC void WaitForDevice(const dali::Tensor<GPUBackend> &t) { |
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.
DLL_PUBLIC void WaitForDevice(const dali::Tensor<GPUBackend> &t) { | |
template<template<GPUBackend>class Container> | |
DLL_PUBLIC void WaitForDevice(const Container<GPUBackend> &t) { |
?
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.
That's the other alternative, I just went with two overloads, I guess a coin flip to decide.
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.
Up to you
CI MESSAGE: [3063967]: BUILD FAILED |
Keep escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
The type was previously implicit in the allocation Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
1fe9a0a
to
1effe9f
Compare
!build |
CI MESSAGE: [3064661]: BUILD STARTED |
CI MESSAGE: [3064661]: BUILD PASSED |
using Buffer<Backend>::SetGrowthFactor; | ||
using Buffer<Backend>::SetShrinkThreshold; | ||
using Buffer<Backend>::GetGrowthFactor; | ||
using Buffer<Backend>::GetShrinkThreshold; |
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.
Do we need those 4?
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Change TensorList Buffer inheritance to private, and reexpose the old API. Keep the buffer-access methods private. Add escape-hatch functions for the purpose of Pipeline output. This is intended as intermediate step, the main purpose is to not introduce the access to the underlying buffer again into the code-base. Get rid of those functions from TL tests. Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
Description
What happened in this PR
Keep escape-hatch functions for the purpose of Pipeline
output.
This is intended as intermediate step, the main
purpose is to not introduce the access to the underlying
buffer again into the code-base.
Get rid of those functions from TL tests.
Additional information
Affected modules and functionalities:
Buffer, Tensor, Tensor List, Pipeline outputs
Key points relevant for the review:
Checklist
Tests
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: DALI-2255