Skip to content

Commit 4b29b30

Browse files
Add OsContext class in shared code
Change-Id: If5aea2126abe1b892068af9ca53e7f448e5b85a6
1 parent bc12389 commit 4b29b30

File tree

13 files changed

+189
-15
lines changed

13 files changed

+189
-15
lines changed

runtime/os_interface/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_BASE
2626
${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_manager.cpp
2727
${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_manager.h
2828
${CMAKE_CURRENT_SOURCE_DIR}/device_factory.h
29+
${CMAKE_CURRENT_SOURCE_DIR}/os_context.h
2930
${CMAKE_CURRENT_SOURCE_DIR}/os_inc_base.h
3031
${CMAKE_CURRENT_SOURCE_DIR}/os_interface.h
3132
${CMAKE_CURRENT_SOURCE_DIR}/os_library.h

runtime/os_interface/linux/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ set(RUNTIME_SRCS_OS_INTERFACE_LINUX
4545
${CMAKE_CURRENT_SOURCE_DIR}/drm_null_device.h
4646
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config.cpp
4747
${CMAKE_CURRENT_SOURCE_DIR}/linux_inc.cpp
48-
${CMAKE_CURRENT_SOURCE_DIR}/os_thread_linux.cpp
49-
${CMAKE_CURRENT_SOURCE_DIR}/os_thread_linux.h
48+
${CMAKE_CURRENT_SOURCE_DIR}/os_context_linux.cpp
5049
${CMAKE_CURRENT_SOURCE_DIR}/os_inc.h
5150
${CMAKE_CURRENT_SOURCE_DIR}/os_interface.cpp
5251
${CMAKE_CURRENT_SOURCE_DIR}/os_interface.h
5352
${CMAKE_CURRENT_SOURCE_DIR}/os_library.cpp
5453
${CMAKE_CURRENT_SOURCE_DIR}/os_library.h
54+
${CMAKE_CURRENT_SOURCE_DIR}/os_thread_linux.cpp
55+
${CMAKE_CURRENT_SOURCE_DIR}/os_thread_linux.h
5556
${CMAKE_CURRENT_SOURCE_DIR}/os_time_linux.cpp
5657
${CMAKE_CURRENT_SOURCE_DIR}/os_time_linux.h
5758
${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_linux.cpp
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#include "runtime/os_interface/os_context.h"
24+
25+
namespace OCLRT {
26+
class OsContext::OsContextImpl {};
27+
OsContext::OsContext(OSInterface &osInterface) {
28+
osContextImpl = std::make_unique<OsContext::OsContextImpl>();
29+
}
30+
31+
OsContext::~OsContext() = default;
32+
} // namespace OCLRT

runtime/os_interface/os_context.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#pragma once
24+
#include <memory>
25+
namespace OCLRT {
26+
class OSInterface;
27+
class OsContext {
28+
public:
29+
class OsContextImpl;
30+
OsContext(OSInterface &osInterface);
31+
~OsContext();
32+
OsContextImpl *get() const {
33+
return osContextImpl.get();
34+
};
35+
36+
protected:
37+
std::unique_ptr<OsContextImpl> osContextImpl;
38+
};
39+
} // namespace OCLRT

runtime/os_interface/windows/os_context_win.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,29 @@
2323
#include "runtime/os_interface/windows/os_context_win.h"
2424
#include "runtime/os_interface/windows/wddm/wddm.h"
2525
#include "runtime/os_interface/windows/wddm/wddm_interface.h"
26+
#include "runtime/os_interface/windows/os_interface.h"
2627

2728
namespace OCLRT {
28-
OsContextWin::OsContextWin(Wddm &wddm) : wddm(wddm) {
29+
30+
OsContextWin::OsContextImpl(Wddm &wddm) : wddm(wddm) {
2931
auto wddmInterface = wddm.getWddmInterface();
30-
if (!wddm.createContext(context))
32+
if (!wddmInterface) {
33+
return;
34+
}
35+
if (!wddm.createContext(context)) {
3136
return;
37+
}
3238
if (wddmInterface->hwQueuesSupported()) {
33-
if (!wddmInterface->createHwQueue(wddm.getPreemptionMode(), *this))
39+
if (!wddmInterface->createHwQueue(wddm.getPreemptionMode(), *this)) {
3440
return;
41+
}
3542
}
3643
initialized = wddmInterface->createMonitoredFence(*this);
3744
};
38-
OsContextWin::~OsContextWin() {
39-
wddm.getWddmInterface()->destroyHwQueue(hwQueueHandle);
45+
OsContextWin::~OsContextImpl() {
46+
if (wddm.getWddmInterface()) {
47+
wddm.getWddmInterface()->destroyHwQueue(hwQueueHandle);
48+
}
4049
wddm.destroyContext(context);
4150
}
4251

@@ -47,4 +56,10 @@ void OsContextWin::resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cp
4756
monitoredFence.cpuAddress = cpuAddress;
4857
monitoredFence.gpuAddress = gpuAddress;
4958
}
59+
60+
OsContext::OsContext(OSInterface &osInterface) {
61+
osContextImpl = std::make_unique<OsContextWin>(*osInterface.get()->getWddm());
62+
}
63+
OsContext::~OsContext() = default;
64+
5065
} // namespace OCLRT

runtime/os_interface/windows/os_context_win.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@
2121
*/
2222

2323
#pragma once
24+
#include "runtime/os_interface/os_context.h"
2425
#include "runtime/os_interface/windows/windows_wrapper.h"
2526
#include "runtime/os_interface/windows/windows_defs.h"
2627
#include <d3dkmthk.h>
2728

2829
namespace OCLRT {
29-
class Wddm;
3030

31-
class OsContextWin {
31+
class Wddm;
32+
using OsContextWin = OsContext::OsContextImpl;
33+
class OsContext::OsContextImpl {
3234
public:
33-
OsContextWin() = delete;
34-
OsContextWin(Wddm &wddm);
35-
~OsContextWin();
35+
OsContextImpl() = delete;
36+
OsContextImpl(Wddm &wddm);
37+
~OsContextImpl();
3638
D3DKMT_HANDLE getContext() const {
3739
return context;
3840
}

runtime/os_interface/windows/wddm/wddm.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
#pragma once
24+
#include "runtime/os_interface/os_context.h"
2425
#include "runtime/os_interface/windows/windows_wrapper.h"
2526
#include "runtime/os_interface/windows/windows_defs.h"
2627
#include "runtime/os_interface/windows/wddm/wddm_interface.h"
@@ -45,11 +46,12 @@ class Gdi;
4546
class Gmm;
4647
class LinearStream;
4748
class GmmPageTableMngr;
48-
class OsContextWin;
4949
struct FeatureTable;
5050
struct WorkaroundTable;
5151
struct KmDafListener;
5252

53+
using OsContextWin = OsContext::OsContextImpl;
54+
5355
enum class WddmInterfaceVersion {
5456
Wddm20 = 20,
5557
Wddm23 = 23,

runtime/os_interface/windows/wddm/wddm_interface.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@
2020
* OTHER DEALINGS IN THE SOFTWARE.
2121
*/
2222
#pragma once
23+
#include "runtime/os_interface/os_context.h"
2324
#include "runtime/os_interface/windows/windows_wrapper.h"
2425
#include <d3dkmthk.h>
2526
#include <cstdint>
2627
#include "runtime/helpers/hw_info.h"
2728

2829
namespace OCLRT {
2930
class Gdi;
30-
class OsContextWin;
3131
class Wddm;
32+
33+
using OsContextWin = OsContext::OsContextImpl;
34+
3235
class WddmInterface {
3336
public:
3437
WddmInterface(Wddm &wddm) : wddm(wddm){};

unit_tests/os_interface/linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ set(IGDRCL_SRCS_tests_os_interface_linux
4040
${CMAKE_CURRENT_SOURCE_DIR}/mock_os_time_linux.h
4141
${CMAKE_CURRENT_SOURCE_DIR}/mock_performance_counters_linux.cpp
4242
${CMAKE_CURRENT_SOURCE_DIR}/mock_performance_counters_linux.h
43+
${CMAKE_CURRENT_SOURCE_DIR}/os_context_linux_tests.cpp
4344
${CMAKE_CURRENT_SOURCE_DIR}/os_interface_linux_tests.cpp
4445
${CMAKE_CURRENT_SOURCE_DIR}/os_time_test.cpp
4546
${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_linux_tests.cpp
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#include "runtime/os_interface/os_context.h"
24+
#include "runtime/os_interface/os_interface.h"
25+
#include "gtest/gtest.h"
26+
27+
namespace OCLRT {
28+
29+
TEST(OsContextTest, WhenOsContextIsCreatedThenImplIsAvailable) {
30+
OSInterface osInterface;
31+
auto osContext2 = std::make_unique<OsContext>(osInterface);
32+
EXPECT_NE(nullptr, osContext2->get());
33+
}
34+
} // namespace OCLRT

unit_tests/os_interface/linux/os_interface_linux_tests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* Copyright (c) 2017 - 2018, Intel Corporation
43
*

unit_tests/os_interface/windows/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ set(IGDRCL_SRCS_tests_os_interface_windows
3535
${CMAKE_CURRENT_SOURCE_DIR}/mock_performance_counters_win.cpp
3636
${CMAKE_CURRENT_SOURCE_DIR}/mock_performance_counters_win.h
3737
${CMAKE_CURRENT_SOURCE_DIR}/mock_wddm_memory_manager.h
38+
${CMAKE_CURRENT_SOURCE_DIR}/os_context_win_tests.cpp
3839
${CMAKE_CURRENT_SOURCE_DIR}/os_interface_win_tests.cpp
3940
${CMAKE_CURRENT_SOURCE_DIR}/os_interface_win_tests.h
4041
${CMAKE_CURRENT_SOURCE_DIR}/os_library_win_tests.cpp
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#include "unit_tests/os_interface/windows/wddm_fixture.h"
24+
#include "runtime/os_interface/windows/os_context_win.h"
25+
#include "runtime/os_interface/windows/os_interface.h"
26+
27+
TEST(OsContextTest, givenWddmWhenCreateOsContextBeforeInitWddmThenOsContextIsNotInitialized) {
28+
auto wddm = new WddmMock;
29+
OSInterface osInterface;
30+
osInterface.get()->setWddm(wddm);
31+
auto osContext = std::make_unique<OsContext>(osInterface);
32+
EXPECT_NE(nullptr, osContext->get());
33+
EXPECT_FALSE(osContext->get()->isInitialized());
34+
}
35+
36+
TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInitialized) {
37+
auto wddm = new WddmMock;
38+
OSInterface osInterface;
39+
osInterface.get()->setWddm(wddm);
40+
wddm->init();
41+
auto osContext = std::make_unique<OsContext>(osInterface);
42+
EXPECT_NE(nullptr, osContext->get());
43+
EXPECT_TRUE(osContext->get()->isInitialized());
44+
}

0 commit comments

Comments
 (0)