DALI icon indicating copy to clipboard operation
DALI copied to clipboard

Refactor Tensor Vector

Open klecki opened this issue 3 years ago • 2 comments

Category: Refactoring

Description:

Refactor TensorVector with intention of using it as the only batch object through DALI.

Main changes:

  1. Batch is the source of truth. This breaks away from the design, where depending on the case (contiguous vs noncontiguous) our metadata were kept in the member TensorList or in the first Tensor respectively. This is enabled thanks to better encapsulation where the internal allocation cannot be changed from the outside.

  2. When modifying the batch, care was taken to update the properties (now stored in batch) in the same order as they are defined. There are some exception.

  3. Now setting and copying samples can be verified against all the properties of the batch - they must match.

  4. There are now three options when deciding if the batch should use contiguous allocation. We can either pin the contiguous or noncontiguous modes or allow buffer to change depending on the needs. In the last case, it can be specifically requested during Resize to change to one of the modes.

  5. When Resizing the batch, and a new allocation is needed, we try to use one big allocation if allowed by the selected mode. It yields smaller memory fragmentation

  6. When we convert the buffer to non-contiguous and it had a contiguous backing allocation, we mark the tensors_ that were pointing to that allocation as not sharing, but still aliasing - so we can call Resize() and get a new allocation without the error that we try to reallocate something that shares data

  7. Contents of tensor_list_as_tensor_vector_test.cc are copied from tensor_list_test.cc and adjusted to handle both contiguous and noncontiguous cases. It is necessary to verify the TensorVector conformance to the TensorList requirements but the code is almost identical to the already existing one.

Note: The third commit does some grouping and reordering of the member functions to hopefully allow for better documentation.

If this is inconvenient I can split it into another PR.

Small bugfix for SampleView constructor was included here, I can factor it out as well.

Additional information:

Affected modules and functionalities:

TensorVector

Key points relevant for the review:

TensorVector

Tests:

YES - both new tests added and old tests ported to test the TensorVector as if it was a TensorList.

  • [x] Existing tests apply
  • [x] New tests added
    • [ ] Python tests
    • [x] GTests
    • [ ] Benchmark
    • [ ] Other
  • [ ] N/A

Checklist

Documentation

  • [ ] Existing documentation applies
  • [x] Documentation updated
    • [x] Docstring
    • [ ] Doxygen
    • [ ] RST
    • [ ] Jupyter
    • [ ] Other
  • [ ] N/A

DALI team only

Requirements

  • [ ] Implements new requirements
  • [ ] Affects existing requirements
  • [x] N/A

REQ IDs: DALI-2689

JIRA TASK: N/A

klecki avatar Aug 08 '22 18:08 klecki

CI MESSAGE: [5582837]: BUILD STARTED

dali-automaton avatar Aug 08 '22 18:08 dali-automaton

CI MESSAGE: [5582837]: BUILD PASSED

dali-automaton avatar Aug 09 '22 06:08 dali-automaton

!build

klecki avatar Aug 11 '22 15:08 klecki

CI MESSAGE: [5614349]: BUILD STARTED

dali-automaton avatar Aug 11 '22 15:08 dali-automaton

CI MESSAGE: [5614349]: BUILD FAILED

dali-automaton avatar Aug 11 '22 17:08 dali-automaton

!build

klecki avatar Aug 17 '22 09:08 klecki

CI MESSAGE: [5663966]: BUILD STARTED

dali-automaton avatar Aug 17 '22 09:08 dali-automaton

CI MESSAGE: [5663966]: BUILD FAILED

dali-automaton avatar Aug 17 '22 10:08 dali-automaton

!build

klecki avatar Aug 17 '22 16:08 klecki

CI MESSAGE: [5667155]: BUILD STARTED

dali-automaton avatar Aug 17 '22 16:08 dali-automaton

CI MESSAGE: [5667155]: BUILD FAILED

dali-automaton avatar Aug 17 '22 18:08 dali-automaton

CI MESSAGE: [5667155]: BUILD PASSED

dali-automaton avatar Aug 17 '22 22:08 dali-automaton