Loading...
Searching...
No Matches
gpu_smart_pointer.hpp File Reference

defines convenience classes and functions for using std::shared_ptr and std::unique_ptr with GPU allocated memory. More...

`#include <cuda_runtime.h>`
`#include <memory>`
`#include <opm/common/utility/gpuDecorators.hpp>`
`#include <opm/simulators/linalg/gpuistl/detail/gpu_safe_call.hpp>`
`#include <opm/simulators/linalg/gpuistl/detail/is_gpu_pointer.hpp>`

Go to the source code of this file.

## Classes

class | Opm::gpuistl::PointerView< T >
| A view towards a smart pointer to GPU-allocated memory. More...
class | Opm::gpuistl::PointerView< void >
| Specialization of PointerView for void type This is needed beause we cannot have a PointerView<void> specialization due to dereferincing a void ptr. More...
class | Opm::gpuistl::ValueAsPointer< T >
| A value stored with a pointer interface. More...

## Namespaces

namespace | Opm
| This file contains a set of helper functions used by VFPProd / VFPInj.

## Functions

template<typename T>
std::shared_ptr< T > | Opm::gpuistl::make_gpu_shared_ptr ()
| Creates a shared pointer managing GPU-allocated memory of the specified element type.
template<typename T>
std::shared_ptr< T > | Opm::gpuistl::make_gpu_shared_ptr (const T &value)
| Creates a shared pointer managing GPU-allocated memory of the specified element type.
template<typename T>
auto | Opm::gpuistl::make_gpu_unique_ptr ()
| Creates a unique pointer managing GPU-allocated memory of the specified element type.
template<typename T>
auto | Opm::gpuistl::make_gpu_unique_ptr (const T &value)
| Creates a unique pointer managing GPU-allocated memory of the specified element type.
template<class T>
T | Opm::gpuistl::copyFromGPU (const T *value)
| Copies a value from GPU-allocated memory to the host.
template<class T>
T | Opm::gpuistl::copyFromGPU (const std::shared_ptr< T > &value)
| Copies a value from GPU-allocated memory to the host.
template<class T, class Deleter>
T | Opm::gpuistl::copyFromGPU (const std::unique_ptr< T, Deleter > &value)
| Copies a value from GPU-allocated memory to the host.
template<class T>
void | Opm::gpuistl::copyToGPU (const T &value, T *ptr)
| Copies a value from the host to GPU-allocated memory.
template<class T>
void | Opm::gpuistl::copyToGPU (const T &value, const std::shared_ptr< T > &ptr)
| Copies a value from the host to GPU-allocated memory using a shared_ptr.
template<class T, class Deleter>
void | Opm::gpuistl::copyToGPU (const T &value, const std::unique_ptr< T, Deleter > &ptr)
| Copies a value from the host to GPU-allocated memory using a unique_ptr.
template<class T>
PointerView< T > | Opm::gpuistl::make_view (const std::shared_ptr< T > &ptr)
template<class T, class Deleter>
PointerView< T > | Opm::gpuistl::make_view (const std::unique_ptr< T, Deleter > &ptr)

## Detailed Description

defines convenience classes and functions for using std::shared_ptr and std::unique_ptr with GPU allocated memory.

## Function Documentation

## copyFromGPU() [1/3]

template<class T>

T Opm::gpuistl::copyFromGPU | ( | const std::shared_ptr< T > & | value | ) |

Copies a value from GPU-allocated memory to the host.

Parameters

  value | A shared pointer to the value on the GPU.

Returns
  The value copied from the GPU.

Note
  This function is involves a sychronization point, and should be used with care.

## copyFromGPU() [2/3]

template<class T, class Deleter>

T Opm::gpuistl::copyFromGPU | ( | const std::unique_ptr< T, Deleter > & | value | ) |

Copies a value from GPU-allocated memory to the host.

Template Parameters

  Deleter | The custom deleter type.

Parameters

  value | A unique pointer to the value on the GPU (with a custom deleter).

Returns
  The value copied from the GPU.

Note
  This function is involves a sychronization point, and should be used with care.

## copyFromGPU() [3/3]

template<class T>

T Opm::gpuistl::copyFromGPU | ( | const T * | value | ) |

Copies a value from GPU-allocated memory to the host.

Parameters

  value | A pointer to the value on the GPU.

Returns
  The value copied from the GPU.

Note
  This function is involves a sychronization point, and should be used with care.

## copyToGPU() [1/3]

template<class T>

void Opm::gpuistl::copyToGPU | ( | const T & | value,
|  | const std::shared_ptr< T > & | ptr )

Copies a value from the host to GPU-allocated memory using a shared_ptr.

Parameters

  value | The value to copy to the GPU.
  ptr | A shared_ptr to the GPU-allocated memory.

Note
  This function involves a synchronization point, and should be used with care.

## copyToGPU() [2/3]

template<class T, class Deleter>

void Opm::gpuistl::copyToGPU | ( | const T & | value,
|  | const std::unique_ptr< T, Deleter > & | ptr )

Copies a value from the host to GPU-allocated memory using a unique_ptr.

Template Parameters

  Deleter | The custom deleter type.

Parameters

  value | The value to copy to the GPU.
  ptr | A unique_ptr to the GPU-allocated memory (with a custom deleter).

Note
  This function involves a synchronization point, and should be used with care.

## copyToGPU() [3/3]

template<class T>

void Opm::gpuistl::copyToGPU | ( | const T & | value,
|  | T * | ptr )

Copies a value from the host to GPU-allocated memory.

Parameters

  value | The value to copy to the GPU.
  ptr | A pointer to the GPU-allocated memory.

Note
  This function is involves a sychronization point, and should be used with care.

## make_gpu_shared_ptr() [1/2]

template<typename T>

std::shared_ptr< T > Opm::gpuistl::make_gpu_shared_ptr | ( |  | ) |

Creates a shared pointer managing GPU-allocated memory of the specified element type.

This function allocates memory on the GPU for the type `T`, using `cudaMalloc`. It returns a `std::shared_ptr` that automatically handles the release of GPU memory with cudaFree when no longer in use.

Template Parameters

  T | The element type to allocate on the GPU.

Returns
  A std::shared_ptr to the GPU-allocated memory.

## make_gpu_shared_ptr() [2/2]

template<typename T>

std::shared_ptr< T > Opm::gpuistl::make_gpu_shared_ptr | ( | const T & | value | ) |

Creates a shared pointer managing GPU-allocated memory of the specified element type.

This function allocates memory on the GPU for the type `T`, using `cudaMalloc`. It returns a std::shared_ptr that automatically handles the release of GPU memory with cudaFree when no longer in use.

Template Parameters

  T | The element type to allocate on the GPU.

Parameters

  value | The value to copy to the GPU-allocated memory.

Returns
  A std::shared_ptr to the GPU-allocated memory.

## make_gpu_unique_ptr() [1/2]

template<typename T>

auto Opm::gpuistl::make_gpu_unique_ptr | ( |  | ) |

Creates a unique pointer managing GPU-allocated memory of the specified element type.

This function allocates memory on the GPU for the type `T`, using `cudaMalloc` . It returns a std::unique_ptr that automatically handles the release of GPU memory with cudaFree when no longer in use.

Template Parameters

  T | The element type to allocate on the GPU.

Returns
  A std::unique_ptr to the GPU-allocated memory.

## make_gpu_unique_ptr() [2/2]

template<typename T>

auto Opm::gpuistl::make_gpu_unique_ptr | ( | const T & | value | ) |

Creates a unique pointer managing GPU-allocated memory of the specified element type.

This function allocates memory on the GPU for the type `T`, using `cudaMalloc`. It returns a std::unique_ptr that automatically handles the release of GPU memory with cudaFree when no longer in use.

Template Parameters

  T | The element type to allocate on the GPU.

Parameters

  value | The value to copy to the GPU-allocated memory.

Returns
  A std::unique_ptr to the GPU-allocated memory.