forked from intel/llvm
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL][Graph] Support for native-command
WIP Prototype [sycl_ext_codeplay_enqueue_native_command](https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/experimental/sycl_ext_codeplay_enqueue_native_command.asciidoc) support for SYCL-Graph. TODO: * buffer support * HIP/Level-Zero/OpenCL native tests * spec wording
- Loading branch information
Showing
12 changed files
with
296 additions
and
10 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
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
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
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
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
81 changes: 81 additions & 0 deletions
81
sycl/test-e2e/Graph/NativeCommand/native_cuda_explicit_usm.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,81 @@ | ||
// RUN: %{build} -g -o %t.out -lcuda | ||
// RUN: %{run} %t.out | ||
// REQUIRES: cuda | ||
|
||
#include "../graph_common.hpp" | ||
#include <cuda.h> | ||
#include <sycl/backend.hpp> | ||
#include <sycl/interop_handle.hpp> | ||
|
||
int main() { | ||
queue Queue; | ||
|
||
int *PtrX = malloc_device<int>(Size, Queue); | ||
int *PtrY = malloc_device<int>(Size, Queue); | ||
|
||
exp_ext::command_graph Graph{Queue}; | ||
|
||
Graph.begin_recording(Queue); | ||
|
||
auto EventA = Queue.submit([&](handler &CGH) { | ||
CGH.single_task([=]() { | ||
for (size_t i = 0; i < Size; i++) { | ||
PtrX[i] = i; | ||
PtrY[i] = 0; | ||
} | ||
}); | ||
}); | ||
|
||
auto EventB = Queue.submit([&](handler &CGH) { | ||
CGH.depends_on(EventA); | ||
|
||
CGH.ext_codeplay_enqueue_native_command([=](interop_handle IH) { | ||
if (IH.has_graph()) { | ||
CUgraph NativeGraph = IH.get_native_graph<backend::ext_oneapi_cuda>(); | ||
|
||
CUDA_MEMCPY3D Params; | ||
std::memset(&Params, 0, sizeof(CUDA_MEMCPY3D)); | ||
Params.srcMemoryType = CU_MEMORYTYPE_DEVICE; | ||
Params.srcDevice = (CUdeviceptr)PtrX; | ||
Params.srcHost = nullptr; | ||
Params.dstMemoryType = CU_MEMORYTYPE_DEVICE; | ||
Params.dstDevice = (CUdeviceptr)PtrY, Params.dstHost = nullptr; | ||
Params.WidthInBytes = Size * sizeof(int); | ||
Params.Height = 1; | ||
Params.Depth = 1; | ||
|
||
CUgraphNode Node; | ||
CUcontext Context = IH.get_native_context<backend::ext_oneapi_cuda>(); | ||
auto Res = cuGraphAddMemcpyNode(&Node, NativeGraph, nullptr, 0, &Params, | ||
Context); | ||
assert(Res == CUDA_SUCCESS); | ||
} else { | ||
assert(false && "Native Handle should have a graph"); | ||
} | ||
}); | ||
}); | ||
|
||
Queue.submit([&](handler &CGH) { | ||
CGH.depends_on(EventB); | ||
CGH.parallel_for(range<1>{Size}, [=](id<1> it) { PtrY[it] *= 2; }); | ||
}); | ||
|
||
Graph.end_recording(); | ||
|
||
auto ExecGraph = Graph.finalize(); | ||
Queue.ext_oneapi_graph(ExecGraph).wait(); | ||
|
||
std::vector<int> HostData(Size); | ||
|
||
Queue.copy(PtrY, HostData.data(), Size).wait(); | ||
for (size_t i = 0; i < Size; i++) { | ||
const int Ref = i * 2; | ||
assert(check_value(Ref, HostData[i], | ||
std::string("HostData at index ") + std::to_string(i))); | ||
} | ||
|
||
free(PtrX, Queue); | ||
free(PtrY, Queue); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.