Skip to content

Commit fe5bc76

Browse files
authored
Merge pull request #1102 from hdelan/adapter-batch1
[HIP] Adapter PR batch
2 parents 47af3ee + 3e1f163 commit fe5bc76

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

source/adapters/hip/context.hpp

+7-27
Original file line numberDiff line numberDiff line change
@@ -112,45 +112,25 @@ struct ur_context_handle_t_ {
112112
};
113113

114114
namespace {
115-
/// RAII type to guarantee recovering original HIP context
116-
/// Scoped context is used across all UR HIP plugin implementation
117-
/// to activate the UR Context on the current thread, matching the
118-
/// HIP driver semantics where the context used for the HIP Driver
119-
/// API is the one active on the thread.
120-
/// The implementation tries to avoid replacing the hipCtx_t if it cans
115+
/// Scoped context is used across all UR HIP plugin implementation to activate
116+
/// the native Context on the current thread. The ScopedContext does not
117+
/// reinstate the previous context as all operations in the hip adapter that
118+
/// require an active context, set the active context and don't rely on context
119+
/// reinstation
121120
class ScopedContext {
122-
hipCtx_t Original;
123-
bool NeedToRecover;
124-
125121
public:
126-
ScopedContext(ur_device_handle_t hDevice) : NeedToRecover{false} {
122+
ScopedContext(ur_device_handle_t hDevice) {
123+
hipCtx_t Original{};
127124

128125
if (!hDevice) {
129126
throw UR_RESULT_ERROR_INVALID_DEVICE;
130127
}
131128

132-
// FIXME when multi device context are supported in HIP adapter
133129
hipCtx_t Desired = hDevice->getNativeContext();
134130
UR_CHECK_ERROR(hipCtxGetCurrent(&Original));
135131
if (Original != Desired) {
136132
// Sets the desired context as the active one for the thread
137133
UR_CHECK_ERROR(hipCtxSetCurrent(Desired));
138-
if (Original == nullptr) {
139-
// No context is installed on the current thread
140-
// This is the most common case. We can activate the context in the
141-
// thread and leave it there until all the UR context referring to the
142-
// same underlying HIP context are destroyed. This emulates
143-
// the behaviour of the HIP runtime api, and avoids costly context
144-
// switches. No action is required on this side of the if.
145-
} else {
146-
NeedToRecover = true;
147-
}
148-
}
149-
}
150-
151-
~ScopedContext() {
152-
if (NeedToRecover) {
153-
UR_CHECK_ERROR(hipCtxSetCurrent(Original));
154134
}
155135
}
156136
};

source/adapters/hip/ur_interface_loader.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,22 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetUsmP2PExpProcAddrTable(
304304
return retVal;
305305
}
306306

307+
// TODO: Implement
308+
UR_DLLEXPORT ur_result_t UR_APICALL urGetBindlessImagesExpProcAddrTable(
309+
ur_api_version_t, ur_bindless_images_exp_dditable_t *) {
310+
// This needs to return UR_RESULT_SUCCESS or else the platform can't be
311+
// initialized
312+
return UR_RESULT_SUCCESS;
313+
}
314+
315+
// TODO: Implement
316+
UR_DLLEXPORT ur_result_t UR_APICALL
317+
urGetUSMExpProcAddrTable(ur_api_version_t, ur_usm_exp_dditable_t *) {
318+
// This needs to return UR_RESULT_SUCCESS or else the platform can't be
319+
// initialized
320+
return UR_RESULT_SUCCESS;
321+
}
322+
307323
UR_DLLEXPORT ur_result_t UR_APICALL urGetVirtualMemProcAddrTable(
308324
ur_api_version_t version, ///< [in] API version requested
309325
ur_virtual_mem_dditable_t

0 commit comments

Comments
 (0)