Skip to content
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

Add inspector::is_trivially_nestable. #986

Merged
merged 1 commit into from May 6, 2024
Merged

Conversation

1uc
Copy link
Collaborator

@1uc 1uc commented Apr 19, 2024

We need this because std::span is considered std::is_trivially_copyable.

@1uc 1uc force-pushed the 1uc/is_trivially_nestable branch from 2fe2b30 to 71c77c6 Compare April 19, 2024 12:52
@1uc 1uc marked this pull request as ready for review April 19, 2024 13:35
@1uc 1uc requested a review from alkino April 19, 2024 14:16
@1uc 1uc mentioned this pull request Apr 19, 2024
@1uc 1uc requested a review from matz-e May 6, 2024 12:11
@1uc 1uc merged commit b77955e into master May 6, 2024
34 checks passed
@1uc 1uc deleted the 1uc/is_trivially_nestable branch May 6, 2024 14:23
@PhilipDeegan
Copy link
Contributor

PhilipDeegan commented May 6, 2024

we're seeing an error now like RuntimeError: Not possible to serialize a T* I'm guessing because of this...

testing locally without this commit to be sure

edit: no error confirmed after popping current top two commits (including this one)

@1uc
Copy link
Collaborator Author

1uc commented May 6, 2024

Thanks for letting us know. I've checked the PR again, and nothing sticks out as wrong. Do you know what T is and if T* is inside some other container, the type of that container?

@PhilipDeegan
Copy link
Contributor

PhilipDeegan commented May 6, 2024

T is a double in this context, but we do some pointer casting to force a 1d vector data pointer into a 2 or 3d dataset

which is feasibly not how it should be done, but it's what has worked until now

template<std::size_t dim, typename Data>
NO_DISCARD auto pointer_dim_caster(Data* data)
{
    if constexpr (dim == 1)
        return data;
    if constexpr (dim == 2)
        return reinterpret_cast<Data const** const>(data);
    if constexpr (dim == 3)
        return reinterpret_cast<Data const*** const>(data);
}

@1uc
Copy link
Collaborator Author

1uc commented May 6, 2024

Yes! That was an interesting surprise. We still have a test for a variation using write_raw here:

std::vector<datatype> const t1(DIMS[0] * DIMS[1] * DIMS[2], 1);
auto raw_3d_vec_const = reinterpret_cast<datatype const* const* const*>(t1.data());
dataset.write_raw(raw_3d_vec_const);

I see three options:

  • Use write_raw without (or with) the magic in pointer_dim_caster.
  • Use the almost ready reshapeMemSpace, see Implement squeeze and reshape. #991. Comments are welcome.
  • Use mdspan which should be one of the next things I'd like to implement.

@PhilipDeegan
Copy link
Contributor

what we're doing is essentially the same as the legacy test, which I'm surprised if it's passing

I can test write_raw without the reinterpret_cast, as the shape given is the correct dimension
we have no plans for C++23 right now

@PhilipDeegan
Copy link
Contributor

without the reinterpret_cast I get
image

@PhilipDeegan
Copy link
Contributor

oh I wasn't using write_raw, testing...

@1uc
Copy link
Collaborator Author

1uc commented May 6, 2024

The write_raw doesn't care about dimensions and such, it's just a very shallow wrapper:

inline void SliceTraits<Derivate>::write_raw(const T* buffer,
const DataType& mem_datatype,
const DataTransferProps& xfer_props) {
const auto& slice = static_cast<const Derivate&>(*this);
detail::h5d_write(details::get_dataset(slice).getId(),
mem_datatype.getId(),
details::get_memspace_id(slice),
slice.getSpace().getId(),
xfer_props.getId(),
static_cast<const void*>(buffer));
}

The type of the pointer doesn't matter, they're all converted to void * and sent to HDF5.

@PhilipDeegan
Copy link
Contributor

it seems ok with write_raw and no reintrepret_cast 👍

@1uc
Copy link
Collaborator Author

1uc commented May 6, 2024

Glad to hear that!

@1uc
Copy link
Collaborator Author

1uc commented May 9, 2024

This change will be documented in the Migration Guide via #996.

Migration Guide: https://bluebrain.github.io/HighFive/md__2home_2runner_2work_2_high_five_2_high_five_2doc_2migration__guide.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants