Skip to content

feat: expose HostMemoryOrVec via API#104

Open
theHamsta wants to merge 1 commit into
rustnn:mainfrom
theHamsta:hostmemory-or-vec
Open

feat: expose HostMemoryOrVec via API#104
theHamsta wants to merge 1 commit into
rustnn:mainfrom
theHamsta:hostmemory-or-vec

Conversation

@theHamsta

Copy link
Copy Markdown
Contributor

Since I needed the same primitive also for RustNN we could expose it in the trtx API. This helper is commonly when you either get owned engine bytes from TensorRT or from a cache.

@theHamsta theHamsta force-pushed the hostmemory-or-vec branch 2 times, most recently from 8c6b456 to 5d1483e Compare May 28, 2026 06:28
Since I needed the same primitive also for RustNN we could expose
it in the trtx API. This helper is commonly when you either
get owned engine bytes from TensorRT or from a cache.
@theHamsta theHamsta force-pushed the hostmemory-or-vec branch from 5d1483e to 19c18dc Compare May 28, 2026 07:01
@theHamsta

theHamsta commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

This could also be

enum HostMemoryOrVec<'memory> {
    HostMemory(HostMemory<'memory>),
    Cow(Cow<'memory, [u8]>),
}

impl<'memory> AsRef<[u8]> for HostMemoryOrVec<'memory> {
    fn as_ref(&self) -> &[u8] {
        match self {
            HostMemoryOrVec::HostMemory(host_memory) => host_memory.as_ref(),
            HostMemoryOrVec::Cow(items) => items.as_ref(),
        }
    }
}

impl<'memory> Deref for HostMemoryOrVec<'memory> {
    type Target = [u8];

    fn deref(&self) -> &Self::Target {
        self.as_ref()
    }
}

impl<'buffer> From<HostMemory<'buffer>> for HostMemoryOrVec<'buffer> {
    fn from(value: HostMemory<'buffer>) -> Self {
        HostMemoryOrVec::HostMemory(value)
    }
}

impl<'memory> From<Cow<'memory, [u8]>> for HostMemoryOrVec<'memory> {
    fn from(value: Cow<'memory, [u8]>) -> Self {
        HostMemoryOrVec::Cow(value)
    }
}

so probably better leave to users to implement it themselves 🤷 ?

@theHamsta theHamsta mentioned this pull request Jun 3, 2026
5 tasks
@mtavenrath

Copy link
Copy Markdown
Contributor

Can you please update the PR using the Cow variant?

HostmMemoryOrVec is descriptive, but might not be true if this struct gets enhanced. Since HostMemory is already taken other potential names in the trtx namespace might be

Buffer
HostMemoryVariant
Bytes
BytesArray

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.

2 participants