TRIQS/nda
2.0.0
Multi-dimensional array library for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
memset.hpp
Go to the documentation of this file.
1
// Copyright (c) 2022--present, The Simons Foundation
2
// This file is part of TRIQS/nda and is licensed under the Apache License, Version 2.0.
3
// SPDX-License-Identifier: Apache-2.0
4
// See LICENSE in the root of this distribution for details.
5
10
11
#pragma once
12
13
#include "
address_space.hpp
"
14
#include "
../device.hpp
"
15
16
#include <cstring>
17
18
namespace
nda::mem {
19
24
37
template
<AddressSpace AdrSp>
38
void
memset
(
void
*p,
int
value,
size_t
count) {
39
check_adr_sp_valid<AdrSp>
();
40
static_assert
(
nda::have_device
==
nda::have_cuda
,
"Adjust function for new device types"
);
41
42
if
constexpr
(AdrSp ==
Host
) {
43
std::memset(p, value, count);
44
}
else
{
45
device_error_check
(cudaMemset(p, value, count),
"cudaMemset"
);
46
}
47
}
48
66
template
<AddressSpace AdrSp>
67
void
memset2D
(
void
*ptr,
size_t
pitch,
int
value,
size_t
width,
size_t
height) {
68
check_adr_sp_valid<AdrSp>
();
69
static_assert
(
nda::have_device
==
nda::have_cuda
,
"Adjust function for new device types"
);
70
71
if
constexpr
(AdrSp ==
Host
) {
72
auto
*ptri =
static_cast<
unsigned
char
*
>
(ptr);
73
for
(
size_t
i = 0; i < height; ++i, ptri += pitch) std::memset(ptri, value, width);
74
}
else
{
// Device or Unified
75
device_error_check
(cudaMemset2D(ptr, pitch, value, width, height),
"cudaMemset2D"
);
76
}
77
}
78
80
81
}
// namespace nda::mem
address_space.hpp
Provides definitions and type traits involving the different memory address spaces supported by nda.
nda::mem::Host
@ Host
Using declaration for the Host address space (see nda::mem::AddressSpace).
Definition
address_space.hpp:51
device.hpp
Provides GPU and non-GPU specific functionality.
nda::mem::check_adr_sp_valid
static const auto check_adr_sp_valid
Check validity of a set of nda::mem::AddressSpace values.
Definition
address_space.hpp:146
nda::have_cuda
static constexpr bool have_cuda
Constexpr variable that is true if the project is configured with CUDA support.
Definition
device.hpp:135
nda::mem::memset2D
void memset2D(void *ptr, size_t pitch, int value, size_t width, size_t height)
Call CUDA's cudaMemset2D function or simulate its behavior on the Host based on the given address spa...
Definition
memset.hpp:67
device_error_check
#define device_error_check(ARG1, ARG2)
Trigger a compilation error every time the nda::device_error_check function is called.
Definition
device.hpp:129
nda::have_device
static constexpr bool have_device
Constexpr variable that is true if the project is configured with GPU support.
Definition
device.hpp:132
nda::mem::memset
void memset(void *p, int value, size_t count)
Call the correct memset function based on the given address space.
Definition
memset.hpp:38
nda
mem
memset.hpp
Generated by
1.17.0