|
| 1 | +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ |
| 2 | +/* |
| 3 | + * Copyright (c) 2024 Advanced Micro Devices, Inc. All Rights reserved. |
| 4 | + * $COPYRIGHT$ |
| 5 | + * |
| 6 | + * Additional copyrights may follow |
| 7 | + * |
| 8 | + * $HEADER$ |
| 9 | + */ |
| 10 | +#include "opal_config.h" |
| 11 | + |
| 12 | +#include "opal/mca/smsc/base/base.h" |
| 13 | +#include "opal/mca/smsc/accelerator/smsc_accelerator_internal.h" |
| 14 | +#include "opal/mca/accelerator/accelerator.h" |
| 15 | +#include "opal/mca/accelerator/base/base.h" |
| 16 | + |
| 17 | +static int mca_smsc_accelerator_component_register(void); |
| 18 | +static int mca_smsc_accelerator_component_open(void); |
| 19 | +static int mca_smsc_accelerator_component_close(void); |
| 20 | +static int mca_smsc_accelerator_component_query(void); |
| 21 | +static mca_smsc_module_t *mca_smsc_accelerator_component_enable(void); |
| 22 | + |
| 23 | +#define MCA_SMSC_ACCELERATOR_DEFAULT_PRIORITY 80 |
| 24 | +static const int mca_smsc_accelerator_default_priority = MCA_SMSC_ACCELERATOR_DEFAULT_PRIORITY; |
| 25 | + |
| 26 | +mca_smsc_accelerator_component_t mca_smsc_accelerator_component = { |
| 27 | + .super = { |
| 28 | + .smsc_version = { |
| 29 | + MCA_SMSC_DEFAULT_VERSION("accelerator"), |
| 30 | + .mca_open_component = mca_smsc_accelerator_component_open, |
| 31 | + .mca_close_component = mca_smsc_accelerator_component_close, |
| 32 | + .mca_register_component_params = mca_smsc_accelerator_component_register, |
| 33 | + }, |
| 34 | + .priority = MCA_SMSC_ACCELERATOR_DEFAULT_PRIORITY, |
| 35 | + .query = mca_smsc_accelerator_component_query, |
| 36 | + .enable = mca_smsc_accelerator_component_enable, |
| 37 | + }, |
| 38 | +}; |
| 39 | + |
| 40 | +static int mca_smsc_accelerator_component_register(void) |
| 41 | +{ |
| 42 | + mca_smsc_base_register_default_params(&mca_smsc_accelerator_component.super, |
| 43 | + mca_smsc_accelerator_default_priority); |
| 44 | + return OPAL_SUCCESS; |
| 45 | +} |
| 46 | + |
| 47 | +static int mca_smsc_accelerator_component_open(void) |
| 48 | +{ |
| 49 | + return OPAL_SUCCESS; |
| 50 | +} |
| 51 | + |
| 52 | +static int mca_smsc_accelerator_component_close(void) |
| 53 | +{ |
| 54 | + if (mca_smsc_accelerator_module.rcache) { |
| 55 | + (void) mca_rcache_base_module_destroy(mca_smsc_accelerator_module.rcache); |
| 56 | + mca_smsc_accelerator_module.rcache = NULL; |
| 57 | + } |
| 58 | + |
| 59 | + return OPAL_SUCCESS; |
| 60 | +} |
| 61 | + |
| 62 | +static int mca_smsc_accelerator_component_query(void) |
| 63 | +{ |
| 64 | + if (0 == strcmp(opal_accelerator_base_selected_component.base_version.mca_component_name, |
| 65 | + "null")) { |
| 66 | + opal_output_verbose(10, opal_smsc_base_framework.framework_output, |
| 67 | + "smsc:accelerator:component_query: accelerator component is null: disqualifying myself"); |
| 68 | + return OPAL_ERROR; |
| 69 | + } |
| 70 | + |
| 71 | + if (!opal_accelerator.is_ipc_enabled()) { |
| 72 | + opal_output_verbose(10, opal_smsc_base_framework.framework_output, |
| 73 | + "smsc:accelerator:component_query: accelerator component does not have support for IPC operations: disqualifying myself"); |
| 74 | + return OPAL_ERROR; |
| 75 | + } |
| 76 | + |
| 77 | + return OPAL_SUCCESS; |
| 78 | +} |
| 79 | + |
| 80 | + |
| 81 | +static int mca_smsc_accelerator_reg(void *reg_data, void *local_address, size_t size, |
| 82 | + mca_rcache_base_registration_t *reg_handle) |
| 83 | +{ |
| 84 | + mca_smsc_accelerator_registration_handle_t *reg = (mca_smsc_accelerator_registration_handle_t *) reg_handle; |
| 85 | + int ret; |
| 86 | + |
| 87 | + ret = opal_accelerator.get_ipc_handle (mca_smsc_accelerator_module.device_id, local_address, |
| 88 | + ®->ipc_handle); |
| 89 | + memcpy (reg->data.handle.accelerator, reg->ipc_handle.handle, SMSC_ACCELERATOR_HANDLE_SIZE); |
| 90 | + if (OPAL_SUCCESS != ret ) { |
| 91 | + return OPAL_ERROR; |
| 92 | + } |
| 93 | + |
| 94 | + return OPAL_SUCCESS; |
| 95 | +} |
| 96 | + |
| 97 | +static int mca_smsc_accelerator_dereg(void *reg_data, mca_rcache_base_registration_t *reg_handle) |
| 98 | +{ |
| 99 | + mca_smsc_accelerator_registration_handle_t *reg = (mca_smsc_accelerator_registration_handle_t *) reg_handle; |
| 100 | + |
| 101 | + OBJ_DESTRUCT(&(reg->ipc_handle)); |
| 102 | + return OPAL_SUCCESS; |
| 103 | +} |
| 104 | + |
| 105 | +static mca_smsc_module_t *mca_smsc_accelerator_component_enable(void) |
| 106 | +{ |
| 107 | + if (0 > mca_smsc_accelerator_component.super.priority) { |
| 108 | + return NULL; |
| 109 | + } |
| 110 | + |
| 111 | + mca_rcache_base_resources_t rcache_resources = {.cache_name = "smsc_accelerator", |
| 112 | + .reg_data = NULL, |
| 113 | + .sizeof_reg = sizeof( |
| 114 | + mca_smsc_accelerator_registration_handle_t), |
| 115 | + .register_mem = mca_smsc_accelerator_reg, |
| 116 | + .deregister_mem = mca_smsc_accelerator_dereg}; |
| 117 | + |
| 118 | + mca_smsc_accelerator_module.rcache = mca_rcache_base_module_create("grdma", NULL, &rcache_resources); |
| 119 | + if (NULL == mca_smsc_accelerator_module.rcache) { |
| 120 | + return NULL; |
| 121 | + } |
| 122 | + |
| 123 | + /* Not set. Will initialize later */ |
| 124 | + mca_smsc_accelerator_module.device_id = MCA_ACCELERATOR_NO_DEVICE_ID; |
| 125 | + |
| 126 | + mca_smsc_accelerator_module.prev_smsc = mca_smsc; |
| 127 | + if ((NULL != mca_smsc_accelerator_module.prev_smsc) && |
| 128 | + (mca_smsc_accelerator_module.prev_smsc->features & MCA_SMSC_FEATURE_CAN_MAP)) { |
| 129 | + mca_smsc_accelerator_module.super.features |= MCA_SMSC_FEATURE_CAN_MAP; |
| 130 | + } |
| 131 | + |
| 132 | + return &mca_smsc_accelerator_module.super; |
| 133 | +} |
0 commit comments