-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds support for generic client and server hal support to allow sending commands as binary requests over a `hal_transmitter`. Added encoders and decoders for converting hal commands to binary format Add hal_server base class which uses the encoders and decoders and a hal_transmitter to receive hal commands remotely and act on the given hal device. Add a hal_client and hal_device_client base class which can be used with a transmitter to send to a remote server binary commands. Added a hal socket cpu client. Added hal cpu socket based server program.
- Loading branch information
Showing
20 changed files
with
2,222 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright (C) Codeplay Software Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License") with LLVM | ||
# Exceptions; you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux") | ||
# Only builds on linux at the moment | ||
add_subdirectory(hal_cpu_remote_server) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright (C) Codeplay Software Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License") with LLVM | ||
# Exceptions; you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
set(HAL_CPU_REMOTE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../clik/external/hal_cpu) | ||
|
||
# Add the files in directly, rather than drag in as a shared library or take | ||
# all the extra clik code | ||
add_executable(hal_cpu_server_bin | ||
hal_cpu_executable.cpp | ||
${HAL_CPU_REMOTE_SOURCE_DIR}/source/cpu_hal.cpp | ||
${HAL_CPU_REMOTE_SOURCE_DIR}/source/hal_main.cpp | ||
) | ||
|
||
target_compile_definitions(hal_cpu_server_bin PUBLIC -DHAL_CPU_MODE=HAL_CPU_WG_MODE) | ||
target_include_directories(hal_cpu_server_bin PRIVATE | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
${HAL_CPU_REMOTE_SOURCE_DIR}/include | ||
) | ||
|
||
target_link_libraries(hal_cpu_server_bin hal_remote hal_common dl pthread) | ||
|
||
|
||
install(TARGETS hal_cpu_server_bin | ||
LIBRARY DESTINATION bin | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (C) Codeplay Software Limited | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License") with LLVM | ||
// Exceptions; you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations | ||
// under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <unistd.h> | ||
|
||
#include "hal_remote/hal_server.h" | ||
#include "hal_remote/hal_socket_client.h" | ||
#include "hal_remote/hal_socket_transmitter.h" | ||
|
||
int main(int argc, char **argv) { | ||
uint32_t api_version; | ||
auto *hal = get_hal(api_version); | ||
uint16_t port = 0; | ||
std::string node = "127.0.0.1"; | ||
if (const char *env = getenv("HAL_REMOTE_PORT")) { | ||
port = std::stoi(env); | ||
} | ||
|
||
if (const char *env = getenv("HAL_REMOTE_NODE")) { | ||
node = env; | ||
} | ||
|
||
hal::hal_socket_transmitter transmitter(node.c_str(), port); | ||
hal::hal_server::error_code last_error = hal::hal_server::status_success; | ||
auto res = transmitter.start_server(true); | ||
if (res != hal::hal_socket_transmitter::success) { | ||
(void)fprintf(stderr, "Unable to start server on requested port %d\n", | ||
port); | ||
return 1; | ||
} | ||
|
||
hal::hal_server server(&transmitter, hal); | ||
last_error = server.process_commands(); | ||
// Check if the failure was due the transmitter, if so check if connection | ||
// closed, otherwise we have a real error. | ||
if (last_error == hal::hal_server::status_transmitter_failed) { | ||
if (transmitter.get_last_error() != | ||
hal::hal_socket_transmitter::connection_closed) { | ||
(void)fprintf(stderr, "Error with tcp/ip connection\n"); | ||
return 1; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (C) Codeplay Software Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License") with LLVM | ||
# Exceptions; you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
set_property(GLOBAL APPEND PROPERTY KNOWN_HAL_DEVICES "cpu_client") | ||
set_property(GLOBAL PROPERTY HAL_CPU_CLIENT_NAME "cpu_remote") | ||
set_property(GLOBAL PROPERTY HAL_CPU_CLIENT_DEVICE_NAME "ock cpu") | ||
|
||
add_subdirectory(source) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (C) Codeplay Software Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License") with LLVM | ||
# Exceptions; you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
set(HAL_CPU_REMOTE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../clik/external/hal_cpu) | ||
add_library(hal_cpu_client SHARED | ||
# Even though it is remote we need hal_cpu.cpp to get the info | ||
${HAL_CPU_REMOTE_SOURCE_DIR}/source/cpu_hal.cpp | ||
hal_main.cpp | ||
) | ||
|
||
set(HAL_CPU_WG_MODE ON) | ||
|
||
target_compile_definitions(hal_cpu_client PUBLIC -DBUILD_HAL_DLL) | ||
target_compile_definitions(hal_cpu_client PUBLIC -DHAL_CPU_MODE=HAL_CPU_WG_MODE) | ||
|
||
target_include_directories(hal_cpu_client PRIVATE | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
${HAL_CPU_REMOTE_SOURCE_DIR}/include | ||
) | ||
|
||
target_link_libraries(hal_cpu_client hal_remote dl pthread) | ||
|
||
set_target_properties(hal_cpu_client PROPERTIES | ||
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) | ||
|
||
install(TARGETS hal_cpu_client | ||
LIBRARY DESTINATION lib | ||
) |
52 changes: 52 additions & 0 deletions
52
examples/hals/hal_cpu_client/source/hal_cpu_executable.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (C) Codeplay Software Limited | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License") with LLVM | ||
// Exceptions; you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations | ||
// under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <hal_remote/hal_server.h> | ||
#include <hal_remote/hal_socket_client.h> | ||
#include <hal_remote/hal_socket_transmitter.h> | ||
#include <unistd.h> | ||
|
||
int main(int argc, char **argv) { | ||
uint32_t api_version; | ||
auto *hal = get_hal(api_version); | ||
uint16_t port = 0; | ||
if (const char *env = getenv("HAL_REMOTE_PORT")) { | ||
port = atoi(env); | ||
} | ||
|
||
hal::hal_socket_transmitter transmitter(port); | ||
hal::hal_server::error_code last_error = hal::hal_server::status_success; | ||
do { | ||
auto res = transmitter.start_server(true); | ||
if (res != hal::hal_socket_transmitter::success) { | ||
printf("Unable to start server on requested port %d\n", port); | ||
fflush(stdout); | ||
exit(1); | ||
} | ||
|
||
hal::hal_server server(&transmitter, hal); | ||
last_error = server.process_commands(); | ||
// Check if the failure was due the transmitter, if so check if connection | ||
// closed, otherwise we have a real error. | ||
if (last_error == hal::hal_server::status_transmitter_failed && | ||
transmitter.get_last_error() != | ||
hal::hal_socket_transmitter::connection_closed) { | ||
fprintf(stderr, "Error with tcp/ip connection\n"); | ||
exit(1); | ||
} | ||
|
||
} while (last_error == hal::hal_server::status_transmitter_failed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (C) Codeplay Software Limited | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License") with LLVM | ||
// Exceptions; you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations | ||
// under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <cpu_hal.h> | ||
#include <hal_remote/hal_socket_client.h> | ||
|
||
namespace hal { | ||
class hal_cpu_socket_client : public hal::hal_socket_client { | ||
public: | ||
hal_cpu_socket_client() : hal_socket_client(0) { | ||
constexpr static uint32_t implemented_api_version = 6; | ||
static_assert( | ||
implemented_api_version == hal_t::api_version, | ||
"Implemented API version for hal_socket_client does not match hal.h"); | ||
hal_device_info = cpu_hal::setup_cpu_hal_device_info(); | ||
hal_info.platform_name = hal_device_info.target_name; | ||
hal_info.num_devices = 1; | ||
hal_info.api_version = implemented_api_version; | ||
uint32_t port = 0; | ||
if (const char *env = getenv("HAL_REMOTE_PORT")) { | ||
port = atoi(env); | ||
} | ||
set_port(port); | ||
} | ||
|
||
// return generic platform information | ||
const hal::hal_info_t &get_info() override { | ||
std::lock_guard<std::mutex> locker(lock); | ||
return hal_info; | ||
} | ||
|
||
// return generic target information | ||
const hal::hal_device_info_t *device_get_info(uint32_t index) override { | ||
std::lock_guard<std::mutex> locker(lock); | ||
return &hal_device_info; | ||
} | ||
|
||
private: | ||
hal::hal_info_t hal_info; | ||
hal::hal_device_info_t hal_device_info; | ||
}; | ||
} // namespace hal | ||
static hal::hal_cpu_socket_client hal_object; | ||
|
||
hal::hal_t *get_hal(uint32_t &api_version) { | ||
api_version = hal_object.get_info().api_version; | ||
return &hal_object; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.