Add cool quote
[alexxy/gromacs.git] / src / gromacs / gpu_utils / tests / pinnedmemorychecker.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2017, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*! \internal \file
36  * \brief
37  * Tests for GPU memory status checker isHostMemoryPinned() being correct.
38  *
39  * \author Aleksei Iupinov <a.yupinov@gmail.com>
40  */
41 #include "gmxpre.h"
42
43 #include <vector>
44
45 #include <gtest/gtest.h>
46
47 #include "gromacs/gpu_utils/gpu_utils.h"
48 #include "gromacs/gpu_utils/hostallocator.h"
49 #include "gromacs/gpu_utils/pmalloc_cuda.h"
50 #include "gromacs/utility/real.h"
51 #include "gromacs/utility/smalloc.h"
52
53 #include "gputest.h"
54
55 namespace gmx
56 {
57
58 namespace test
59 {
60
61 namespace
62 {
63
64 //! Test fixture
65 using PinnedMemoryCheckerTest = GpuTest;
66
67 TEST_F(PinnedMemoryCheckerTest, DefaultContainerIsRecognized)
68 {
69     std::vector<real> dummy(3, 1.5);
70     EXPECT_FALSE(isHostMemoryPinned(dummy.data()));
71 }
72
73 TEST_F(PinnedMemoryCheckerTest, NonpinnedContainerIsRecognized)
74 {
75     HostVector<real> dummy(3, 1.5);
76     changePinningPolicy(&dummy, PinningPolicy::CannotBePinned);
77     EXPECT_FALSE(isHostMemoryPinned(dummy.data()));
78 }
79
80 TEST_F(PinnedMemoryCheckerTest, PinnedContainerIsRecognized)
81 {
82     HostVector<real> dummy(3, 1.5);
83     changePinningPolicy(&dummy, PinningPolicy::CanBePinned);
84     EXPECT_TRUE(isHostMemoryPinned(dummy.data()));
85 }
86
87 TEST_F(PinnedMemoryCheckerTest, DefaultCBufferIsRecognized)
88 {
89     real *dummy;
90     snew(dummy, 3);
91     EXPECT_FALSE(isHostMemoryPinned(dummy));
92     sfree(dummy);
93 }
94
95 TEST_F(PinnedMemoryCheckerTest, PinnedCBufferIsRecognized)
96 {
97     real *dummy = nullptr;
98     pmalloc((void **)&dummy, 3 * sizeof(real));
99     EXPECT_TRUE(isHostMemoryPinned(dummy));
100     pfree(dummy);
101 }
102
103 } // namespace
104 } // namespace
105 } // namespace