CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
113 lines
2.9 KiB
C++
113 lines
2.9 KiB
C++
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include <hipdnn-gpu-ref/detail/ShallowDeviceOnlyMigratableMemory.hpp>
|
|
#include <hipdnn_data_sdk/utilities/Tensor.hpp>
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <random>
|
|
#include <stdexcept>
|
|
#include <vector>
|
|
|
|
namespace hipdnn_gpu_ref
|
|
{
|
|
|
|
/// Non-owning tensor that wraps an existing device pointer.
|
|
/// Mirrors hipdnn_data_sdk::utilities::ShallowTensor but for device memory.
|
|
template <class T>
|
|
class ShallowGpuTensor : public hipdnn_data_sdk::utilities::TensorBase<T>
|
|
{
|
|
using Base = hipdnn_data_sdk::utilities::TensorBase<T>;
|
|
|
|
public:
|
|
ShallowGpuTensor(void* deviceMemory,
|
|
const std::vector<int64_t>& dims,
|
|
const std::vector<int64_t>& strides)
|
|
: _dims(dims)
|
|
, _strides(strides)
|
|
, _elementCount(Base::calculateItemCount(dims))
|
|
, _packed(Base::computeIsPacked(dims, strides))
|
|
{
|
|
_memory = detail::ShallowDeviceOnlyMigratableMemory<T>(
|
|
deviceMemory, Base::calculateElementSpace(dims, strides));
|
|
}
|
|
|
|
ShallowGpuTensor(const ShallowGpuTensor&) = delete;
|
|
ShallowGpuTensor& operator=(const ShallowGpuTensor&) = delete;
|
|
|
|
ShallowGpuTensor(ShallowGpuTensor&&) = default;
|
|
ShallowGpuTensor& operator=(ShallowGpuTensor&&) = default;
|
|
|
|
const std::vector<int64_t>& dims() const override
|
|
{
|
|
return _dims;
|
|
}
|
|
|
|
const std::vector<int64_t>& strides() const override
|
|
{
|
|
return _strides;
|
|
}
|
|
|
|
bool isPacked() const override
|
|
{
|
|
return _packed;
|
|
}
|
|
|
|
size_t elementCount() const override
|
|
{
|
|
return _elementCount;
|
|
}
|
|
|
|
size_t elementSpace() const override
|
|
{
|
|
return _memory.count();
|
|
}
|
|
|
|
const hipdnn_data_sdk::utilities::MigratableMemoryBase<T>& memory() const override
|
|
{
|
|
return _memory;
|
|
}
|
|
|
|
hipdnn_data_sdk::utilities::MigratableMemoryBase<T>& memory() override
|
|
{
|
|
return _memory;
|
|
}
|
|
|
|
void fillWithValue([[maybe_unused]] T value) override
|
|
{
|
|
throwNotSupported();
|
|
}
|
|
|
|
void fillWithRandomValues([[maybe_unused]] T min,
|
|
[[maybe_unused]] T max,
|
|
[[maybe_unused]] unsigned int seed = std::random_device{}()) override
|
|
{
|
|
throwNotSupported();
|
|
}
|
|
|
|
size_t fillWithData([[maybe_unused]] const void* data,
|
|
[[maybe_unused]] size_t maxBytesCopied) override
|
|
{
|
|
throwNotSupported();
|
|
return 0;
|
|
}
|
|
|
|
private:
|
|
static void throwNotSupported()
|
|
{
|
|
throw std::runtime_error(
|
|
"ShallowGpuTensor does not support this operation. Use the Tensor class instead.");
|
|
}
|
|
|
|
detail::ShallowDeviceOnlyMigratableMemory<T> _memory;
|
|
std::vector<int64_t> _dims;
|
|
std::vector<int64_t> _strides;
|
|
size_t _elementCount;
|
|
bool _packed;
|
|
};
|
|
|
|
} // namespace hipdnn_gpu_ref
|