TRIQS/nda 2.0.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
prefetch.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 Simons Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0.txt
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Authors: Miguel Morales, Nils Wentzell
16
21
22#pragma once
23
24#include "./address_space.hpp"
25#include "../device.hpp"
26
27#include <cstdlib>
28
29namespace nda::mem {
30
35
36 // MAM: should I keep a specific stream just for prefetching???
47 template <AddressSpace AdrSp>
48 requires((AdrSp == Host or AdrSp == Device) and have_cuda)
49 void prefetch(void *p, size_t count) {
50 if constexpr (AdrSp == Host) {
51 device_error_check(cudaMemPrefetchAsync(p, count, cudaCpuDeviceId, 0), "cudaMemPrefetchAsync");
52 } else if constexpr (AdrSp == Device) {
53 int dev = 0;
54 device_error_check(cudaGetDevice(&dev), "cudagetDevice");
55 device_error_check(cudaMemPrefetchAsync(p, count, dev, 0), "cudaMemPrefetchAsync");
56 }
57 }
58
60
61} // namespace nda::mem
Provides definitions and type traits involving the different memory address spaces supported by nda.
@ Host
Using declaration for the Host address space (see nda::mem::AddressSpace).
@ Device
Using declaration for the Device address space (see nda::mem::AddressSpace).
Provides GPU and non-GPU specific functionality.
static constexpr bool have_cuda
Constexpr variable that is true if the project is configured with CUDA support.
Definition device.hpp:202
#define device_error_check(ARG1, ARG2)
Trigger a compilation error every time the nda::device_error_check function is called.
Definition device.hpp:196
void prefetch(void *p, size_t count)
Prefetch memory to the specified destination location.
Definition prefetch.hpp:49