@@ -917,6 +917,53 @@ struct CUDADeviceTy : public GenericDeviceTy {
917
917
return Plugin::success ();
918
918
}
919
919
920
+ interop_spec_t selectInteropPreference (int32_t InteropType,
921
+ int32_t NumPrefers,
922
+ interop_spec_t *Prefers) override {
923
+ return interop_spec_t {tgt_fr_cuda, {true , 0 }, 0 };
924
+ }
925
+
926
+ Expected<omp_interop_val_t *>
927
+ createInterop (int32_t InteropType, interop_spec_t &InteropSpec) override {
928
+ auto *Ret = new omp_interop_val_t (
929
+ DeviceId, static_cast <kmp_interop_type_t >(InteropType));
930
+ Ret->fr_id = tgt_fr_cuda;
931
+ Ret->vendor_id = omp_vendor_nvidia;
932
+
933
+ if (InteropType == kmp_interop_type_target ||
934
+ InteropType == kmp_interop_type_targetsync) {
935
+ Ret->device_info .Platform = nullptr ;
936
+ Ret->device_info .Device = reinterpret_cast <void *>(Device);
937
+ Ret->device_info .Context = Context;
938
+ }
939
+
940
+ if (InteropType == kmp_interop_type_targetsync) {
941
+ Ret->async_info = new __tgt_async_info ();
942
+ if (auto Err = setContext ())
943
+ return Err;
944
+ CUstream Stream;
945
+ if (auto Err = CUDAStreamManager.getResource (
946
+ *reinterpret_cast <CUstream *>(&Stream)))
947
+ return Err;
948
+
949
+ Ret->async_info ->Queue = Stream;
950
+ }
951
+ return Ret;
952
+ }
953
+
954
+ Error releaseInterop (omp_interop_val_t *Interop) override {
955
+ if (!Interop)
956
+ return Plugin::success ();
957
+
958
+ if (Interop->async_info ) {
959
+ // TODO: release the stream back to the pool?
960
+ delete Interop->async_info ;
961
+ }
962
+ delete Interop;
963
+
964
+ return Plugin::success ();
965
+ }
966
+
920
967
Error enqueueHostCallImpl (void (*Callback)(void *), void *UserData,
921
968
AsyncInfoWrapperTy &AsyncInfo) override {
922
969
if (auto Err = setContext ())
0 commit comments