Skip to content

Commit

Permalink
Merge pull request #367 from veselypeta/petr/204/repurpose-ur_device_…
Browse files Browse the repository at this point in the history
…init_flags_t

[UR] Add devie type enumerations to urInit()
  • Loading branch information
veselypeta authored Mar 17, 2023
2 parents c54b782 + 7574563 commit 31b10e5
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
6 changes: 5 additions & 1 deletion include/ur.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ class ur_rect_region_t(Structure):
###############################################################################
## @brief Supported device initialization flags
class ur_device_init_flags_v(IntEnum):
GPU = UR_BIT(0) ## initialize GPU device drivers
GPU = UR_BIT(0) ## initialize GPU device drivers.
CPU = UR_BIT(1) ## initialize CPU device drivers.
FPGA = UR_BIT(2) ## initialize FPGA device drivers.
MCA = UR_BIT(3) ## initialize MCA device drivers.
VPU = UR_BIT(4) ## initialize VPU device drivers.

class ur_device_init_flags_t(c_int):
def __str__(self):
Expand Down
8 changes: 6 additions & 2 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ typedef struct ur_rect_region_t {
/// @brief Supported device initialization flags
typedef uint32_t ur_device_init_flags_t;
typedef enum ur_device_init_flag_t {
UR_DEVICE_INIT_FLAG_GPU = UR_BIT(0), ///< initialize GPU device drivers
UR_DEVICE_INIT_FLAG_GPU = UR_BIT(0), ///< initialize GPU device drivers.
UR_DEVICE_INIT_FLAG_CPU = UR_BIT(1), ///< initialize CPU device drivers.
UR_DEVICE_INIT_FLAG_FPGA = UR_BIT(2), ///< initialize FPGA device drivers.
UR_DEVICE_INIT_FLAG_MCA = UR_BIT(3), ///< initialize MCA device drivers.
UR_DEVICE_INIT_FLAG_VPU = UR_BIT(4), ///< initialize VPU device drivers.
/// @cond
UR_DEVICE_INIT_FLAG_FORCE_UINT32 = 0x7fffffff
/// @endcond
Expand Down Expand Up @@ -314,7 +318,7 @@ typedef enum ur_device_init_flag_t {
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `0x1 < device_flags`
/// + `0x1f < device_flags`
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
UR_APIEXPORT ur_result_t UR_APICALL
urInit(
Expand Down
10 changes: 9 additions & 1 deletion scripts/core/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ class: $x
name: $x_device_init_flags_t
etors:
- name: GPU
desc: "initialize GPU device drivers"
desc: "initialize GPU device drivers."
- name: CPU
desc: "initialize CPU device drivers."
- name: FPGA
desc: "initialize FPGA device drivers."
- name: MCA
desc: "initialize MCA device drivers."
- name: VPU
desc: "initialize VPU device drivers."
--- #--------------------------------------------------------------------------
type: function
desc: "Initialize the $OneApi driver(s)"
Expand Down
2 changes: 1 addition & 1 deletion source/loader/layers/validation/ur_valddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ __urdlllocal ur_result_t UR_APICALL urInit(
}

if (context.enableParameterValidation) {
if (0x1 < device_flags) {
if (0x1f < device_flags) {
return UR_RESULT_ERROR_INVALID_ENUMERATION;
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern "C" {
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `0x1 < device_flags`
/// + `0x1f < device_flags`
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
ur_result_t UR_APICALL urInit(
ur_device_init_flags_t device_flags ///< [in] device initialization flags.
Expand Down
2 changes: 1 addition & 1 deletion source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/// - ::UR_RESULT_ERROR_UNINITIALIZED
/// - ::UR_RESULT_ERROR_DEVICE_LOST
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `0x1 < device_flags`
/// + `0x1f < device_flags`
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
ur_result_t UR_APICALL urInit(
ur_device_init_flags_t device_flags ///< [in] device initialization flags.
Expand Down
16 changes: 13 additions & 3 deletions test/conformance/platform/urInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
// SPDX-License-Identifier: MIT
#include <uur/checks.h>

TEST(urInitTest, Success) {
ur_device_init_flags_t device_flags = 0;
using urInitTestWithParam = ::testing::TestWithParam<ur_device_init_flags_t>;
INSTANTIATE_TEST_SUITE_P(
, urInitTestWithParam,
::testing::Values(UR_DEVICE_INIT_FLAG_GPU, UR_DEVICE_INIT_FLAG_CPU,
UR_DEVICE_INIT_FLAG_FPGA, UR_DEVICE_INIT_FLAG_MCA,
UR_DEVICE_INIT_FLAG_VPU,
/* Combinations */
UR_DEVICE_INIT_FLAG_GPU | UR_DEVICE_INIT_FLAG_CPU,
UR_DEVICE_INIT_FLAG_FPGA | UR_DEVICE_INIT_FLAG_VPU));

TEST_P(urInitTestWithParam, Success) {
ur_device_init_flags_t device_flags = GetParam();
ASSERT_SUCCESS(urInit(device_flags));

ur_tear_down_params_t tear_down_params{};
ur_tear_down_params_t tear_down_params{nullptr};
ASSERT_SUCCESS(urTearDown(&tear_down_params));
}

Expand Down

0 comments on commit 31b10e5

Please sign in to comment.