# include <cusolverDn.h>
# include <cusolverSp.h>
# include <cusparse.h>
-#endif
-#include <vector>
+# include <vector>
DEAL_II_NAMESPACE_OPEN
namespace Utilities
*/
~Handle();
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
cusolverDnHandle_t cusolver_dn_handle;
cusolverSpHandle_t cusolver_sp_handle;
* Handle to the cuSPARSE library.
*/
cusparseHandle_t cusparse_handle;
-#endif
};
/**
inline void
malloc(T *&pointer, const unsigned int n_elements)
{
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
cudaError_t cuda_error_code =
cudaMalloc(&pointer, n_elements * sizeof(T));
AssertCuda(cuda_error_code);
-#else
- (void)pointer;
- (void)n_elements;
-#endif
}
/**
inline void
free(T *&pointer)
{
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
cudaError_t cuda_error_code = cudaFree(pointer);
AssertCuda(cuda_error_code);
pointer = nullptr;
-#else
- (void)pointer;
-#endif
}
/**
Number *
allocate_device_data(const std::size_t size)
{
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
Number *device_ptr;
Utilities::CUDA::malloc(device_ptr, size);
return device_ptr;
-#else
- (void)size;
- Assert(
- false,
- ExcMessage(
- "This function can only be used if deal.II is built with CUDA support!"));
-#endif
}
/**
void
delete_device_data(Number *device_ptr) noexcept
{
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
const cudaError_t error_code = cudaFree(device_ptr);
AssertNothrowCuda(error_code);
-#else
- (void)device_ptr;
- AssertNothrow(
- false,
- ExcMessage(
- "This function can only be used if deal.II is built with CUDA support!"));
-#endif
}
/**
inline void
copy_to_host(const T *pointer_dev, std::vector<T> &vector_host)
{
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
cudaError_t cuda_error_code = cudaMemcpy(vector_host.data(),
pointer_dev,
vector_host.size() * sizeof(T),
cudaMemcpyDeviceToHost);
AssertCuda(cuda_error_code);
-#else
- (void)pointer_dev;
- (void)vector_host;
-#endif
}
/**
inline void
copy_to_dev(const std::vector<T> &vector_host, T *pointer_dev)
{
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
cudaError_t cuda_error_code = cudaMemcpy(pointer_dev,
vector_host.data(),
vector_host.size() * sizeof(T),
cudaMemcpyHostToDevice);
AssertCuda(cuda_error_code);
-#else
- (void)vector_host;
- (void)pointer_dev;
-#endif
}
} // namespace CUDA
} // namespace Utilities
DEAL_II_NAMESPACE_CLOSE
-
+#endif
#endif
-#ifdef DEAL_II_COMPILER_CUDA_AWARE
- /**
- * Deleter for unique/shared pointer pointing to an array allocated on the
- * device.
- */
- template <typename Number>
- void
- deleter_device_array(Number *ptr) noexcept
- {
- const cudaError_t cuda_error_code = cudaFree(ptr);
- (void)cuda_error_code;
- AssertNothrow(cuda_error_code == cudaSuccess,
- ExcCudaError(cudaGetErrorString(cuda_error_code)));
- }
-#endif
-
-
-
/**
* Data structure
*/
{
MemorySpaceData()
: values(nullptr, &free)
- , values_dev(nullptr, deleter_device_array<Number>)
+ , values_dev(nullptr, Utilities::CUDA::delete_device_data<Number>)
{}
void