From a0e9b96e52d26fde34a5b4c14ead63dfc07682bf Mon Sep 17 00:00:00 2001 From: "Mrozek, Michal" Date: Fri, 22 Jun 2018 12:54:33 +0200 Subject: [PATCH] Add execution environment. - this class will encapsulate common shared state - platform will create it - clients will increment ref count - platform upon destruction will decrement ref counts - it means that execution environment will be capable of living longer then platform in case there will be dependencies. Change-Id: I0ea7f85ea57448c0e641673f1d15851e50b2b8b2 --- runtime/execution_environment/CMakeLists.txt | 27 +++++++++++ .../execution_environment.cpp | 21 ++++++++ .../execution_environment.h | 28 +++++++++++ runtime/platform/platform.cpp | 4 ++ runtime/platform/platform.h | 3 ++ .../execution_environment/CMakeLists.txt | 25 ++++++++++ .../execution_environment_tests.cpp | 48 +++++++++++++++++++ 7 files changed, 156 insertions(+) create mode 100644 runtime/execution_environment/CMakeLists.txt create mode 100644 runtime/execution_environment/execution_environment.cpp create mode 100644 runtime/execution_environment/execution_environment.h create mode 100644 unit_tests/execution_environment/CMakeLists.txt create mode 100644 unit_tests/execution_environment/execution_environment_tests.cpp diff --git a/runtime/execution_environment/CMakeLists.txt b/runtime/execution_environment/CMakeLists.txt new file mode 100644 index 0000000000..3bcf98c019 --- /dev/null +++ b/runtime/execution_environment/CMakeLists.txt @@ -0,0 +1,27 @@ +# Copyright (c) 2018, Intel Corporation +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. + +set(RUNTIME_SRCS_EXECUTION_ENVIRONMENT + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/execution_environment.h + ${CMAKE_CURRENT_SOURCE_DIR}/execution_environment.cpp +) +target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_EXECUTION_ENVIRONMENT}) +set_property(GLOBAL PROPERTY RUNTIME_SRCS_EXECUTION_ENVIRONMENT ${RUNTIME_SRCS_EXECUTION_ENVIRONMENT}) diff --git a/runtime/execution_environment/execution_environment.cpp b/runtime/execution_environment/execution_environment.cpp new file mode 100644 index 0000000000..6e1de6ff13 --- /dev/null +++ b/runtime/execution_environment/execution_environment.cpp @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2018, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ \ No newline at end of file diff --git a/runtime/execution_environment/execution_environment.h b/runtime/execution_environment/execution_environment.h new file mode 100644 index 0000000000..408c09f2e3 --- /dev/null +++ b/runtime/execution_environment/execution_environment.h @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2018, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "runtime/utilities/reference_tracked_object.h" + +namespace OCLRT { +class ExecutionEnvironment : public ReferenceTrackedObject { +}; +} // namespace OCLRT diff --git a/runtime/platform/platform.cpp b/runtime/platform/platform.cpp index 1462a2e4e5..0f07a42cfb 100644 --- a/runtime/platform/platform.cpp +++ b/runtime/platform/platform.cpp @@ -25,6 +25,7 @@ #include "runtime/compiler_interface/compiler_interface.h" #include "CL/cl_ext.h" #include "runtime/device/device.h" +#include "runtime/execution_environment/execution_environment.h" #include "runtime/gtpin/gtpin_notify.h" #include "runtime/helpers/debug_helpers.h" #include "runtime/helpers/get_info.h" @@ -46,10 +47,13 @@ Platform *platform() { return &platformImpl; } Platform::Platform() { devices.reserve(64); setAsyncEventsHandler(std::unique_ptr(new AsyncEventsHandler())); + executionEnvironment = new ExecutionEnvironment; + executionEnvironment->incRefInternal(); } Platform::~Platform() { shutdown(); + executionEnvironment->decRefInternal(); } cl_int Platform::getInfo(cl_platform_info paramName, diff --git a/runtime/platform/platform.h b/runtime/platform/platform.h index fcd79312df..6650497fb2 100644 --- a/runtime/platform/platform.h +++ b/runtime/platform/platform.h @@ -33,6 +33,7 @@ namespace OCLRT { class CompilerInterface; class Device; class AsyncEventsHandler; +class ExecutionEnvironment; struct HardwareInfo; template <> @@ -65,6 +66,7 @@ class Platform : public BaseObject<_cl_platform_id> { const PlatformInfo &getPlatformInfo() const; AsyncEventsHandler *getAsyncEventsHandler(); std::unique_ptr setAsyncEventsHandler(std::unique_ptr handler); + ExecutionEnvironment *peekExecutionEnvironment() { return executionEnvironment; } protected: enum { @@ -79,6 +81,7 @@ class Platform : public BaseObject<_cl_platform_id> { DeviceVector devices; std::string compilerExtensions; std::unique_ptr asyncEventsHandler; + ExecutionEnvironment *executionEnvironment = nullptr; }; Platform *platform(); diff --git a/unit_tests/execution_environment/CMakeLists.txt b/unit_tests/execution_environment/CMakeLists.txt new file mode 100644 index 0000000000..7a965f876b --- /dev/null +++ b/unit_tests/execution_environment/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright (c) 2018, Intel Corporation +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. + +set(IGDRCL_SRCS_tests_execution_environment + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/execution_environment_tests.cpp +) +target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_execution_environment}) diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp new file mode 100644 index 0000000000..47c62d42ba --- /dev/null +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2018, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "test.h" +#include "runtime/execution_environment/execution_environment.h" +#include "runtime/platform/platform.h" + +using namespace OCLRT; + +TEST(ExecutionEnvironment, givenDefaultConstructorWhenItIsCalledThenExecutionEnvironmentHasInitialRefCountZero) { + ExecutionEnvironment environment; + EXPECT_EQ(0, environment.getRefInternalCount()); + EXPECT_EQ(0, environment.getRefApiCount()); +} + +TEST(ExecutionEnvironment, givenPlatformWhenItIsConstructedThenItCretesExecutionEnvironmentWithOneRefCountInternal) { + std::unique_ptr platform(new Platform); + ASSERT_NE(nullptr, platform->peekExecutionEnvironment()); + EXPECT_EQ(1, platform->peekExecutionEnvironment()->getRefInternalCount()); +} + +TEST(ExecutionEnvironment, givenPlatformAndExecutionEnvironmentWithRefCountsWhenPlatformIsDestroyedThenExecutionEnvironmentIsNotDeleted) { + std::unique_ptr platform(new Platform); + auto executionEnvironment = platform->peekExecutionEnvironment(); + executionEnvironment->incRefInternal(); + platform.reset(); + EXPECT_EQ(1, executionEnvironment->getRefInternalCount()); + executionEnvironment->decRefInternal(); +}