Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / tests / unit / engines / gna / gna_allocator_test.cpp
1 //
2 // Copyright 2016-2018 Intel Corporation.
3 //
4 // This software and the related documents are Intel copyrighted materials,
5 // and your use of them is governed by the express license under which they
6 // were provided to you (End User License Agreement for the Intel(R) Software
7 // Development Products (Version May 2017)). Unless the License provides
8 // otherwise, you may not use, modify, copy, publish, distribute, disclose or
9 // transmit this software or the related documents without Intel's prior
10 // written permission.
11 //
12 // This software and the related documents are provided as is, with no
13 // express or implied warranties, other than those that are expressly
14 // stated in the License.
15 //
16
17 #include "gna_plugin/gna_allocator.hpp"
18
19 #include <vector>
20 #include <thread>
21
22 #include <gtest/gtest.h>
23 #include "gna_plugin/gna_device.hpp"
24 //dummy definitions to work around issue with Linux userspace library
25 typedef unsigned long long time_tsc;
26 typedef struct
27 {
28     time_tsc            start;      // time value on profiler start
29     time_tsc            stop;       // time value on profiler stop
30     time_tsc            passed;     // time passed between start and stop
31 } intel_gna_profiler_tsc;
32
33 void profilerTscStop(intel_gna_profiler_tsc* p) {
34     if (NULL == p) return;
35     p->passed = 0;
36     p->stop = 0;
37     p->start = 0;
38 }
39 void profilerTscStartAccumulate(intel_gna_profiler_tsc* p)
40 {
41     if (NULL == p) return;
42     p->stop = 0;
43     p->start = 0;
44 }
45 void profilerTscStopAccumulate(intel_gna_profiler_tsc* p)
46 {
47     if (NULL == p) return;
48     p->stop = 0;
49     p->passed += p->stop - p->start;
50 }
51
52 class GNAAllocatorTest : public ::testing::Test {
53
54  protected:
55     std::unique_ptr<GNADeviceHelper> gnadevice;
56     void SetUp() override  {
57        // gnadevice.reset(new GNADeviceHelper());
58     }
59 };
60
61 TEST_F(GNAAllocatorTest, canAllocateStdMemory) {
62     auto sp = make_polymorph<std::allocator<uint8_t>>();
63     uint8_t *x = nullptr;
64     ASSERT_NO_THROW(x = sp.allocate(100));
65     ASSERT_NE(x, nullptr);
66     ASSERT_NO_THROW(sp.deallocate(x, 100));
67 }
68
69 TEST_F(GNAAllocatorTest, canAllocateGNAMemory) {
70     //GNA device can be opened one per process for now
71     gnadevice.reset(new GNADeviceHelper());
72     auto sp = make_polymorph<GNAAllocator>(*gnadevice.get());
73     uint8_t *x = nullptr;
74     ASSERT_NO_THROW(x = sp.allocate(100));
75     ASSERT_NE(x, nullptr);
76     ASSERT_NO_THROW(sp.deallocate(x, 100));
77 }
78
79 TEST_F(GNAAllocatorTest, DISABLED_canOpenDevice) {
80     std::thread th([]()
81     {
82         GNADeviceHelper h1;
83     });
84     th.join();
85     std::thread th2([]()
86    {
87        GNADeviceHelper h1;
88    });
89     th2.join();
90 }