EIC Software
Reference for
EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
CpuScalar.hpp
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file CpuScalar.hpp
1
// This file is part of the Acts project.
2
//
3
// Copyright (C) 2020 CERN for the benefit of the Acts project
4
//
5
// This Source Code Form is subject to the terms of the Mozilla Public
6
// License, v. 2.0. If a copy of the MPL was not distributed with this
7
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
9
#pragma once
10
11
#include "Acts/Plugins/Cuda/Utilities/CudaScalar.cu"
12
13
namespace
Acts {
14
15
template
<
typename
var_t>
16
class
CudaScalar
;
17
18
template
<
typename
var_t>
19
class
CpuScalar
{
20
public
:
21
CpuScalar
(
bool
pinned = 0) {
22
m_pinned
= pinned;
23
if
(pinned == 0) {
24
m_hostPtr
=
new
var_t[1];
25
}
else
if
(pinned == 1) {
26
cudaMallocHost(&
m_hostPtr
,
sizeof
(var_t));
27
}
28
}
29
30
CpuScalar
(
CudaScalar<var_t>
* cuScalar,
bool
pinned = 0) {
31
m_pinned
= pinned;
32
if
(pinned == 0) {
33
m_hostPtr
=
new
var_t[1];
34
}
else
if
(pinned == 1) {
35
cudaMallocHost(&
m_hostPtr
,
sizeof
(var_t));
36
}
37
cudaMemcpy(
m_hostPtr
, cuScalar->get(),
sizeof
(var_t),
38
cudaMemcpyDeviceToHost);
39
}
40
41
~CpuScalar
() {
42
if
(!
m_pinned
) {
43
delete
m_hostPtr
;
44
}
else
if
(
m_pinned
&&
m_hostPtr
) {
45
cudaFreeHost(
m_hostPtr
);
46
}
47
}
48
49
var_t*
get
() {
return
m_hostPtr
; }
50
51
void
Set
(var_t val) {
m_hostPtr
[0] = val; }
52
53
private
:
54
var_t*
m_hostPtr
=
nullptr
;
55
size_t
m_size
;
56
bool
m_pinned
;
57
};
58
59
}
// namespace Acts
acts
blob
sPHENIX
Plugins
Cuda
include
Acts
Plugins
Cuda
Utilities
CpuScalar.hpp
Built by
Jin Huang
. updated:
Mon Jan 22 2024 12:43:26
using
1.8.2 with
EIC GitHub integration