Skip to content

Commit 6d0117a

Browse files
committed
Update wait-throw
1 parent 0aa566b commit 6d0117a

File tree

6 files changed

+38
-21
lines changed

6 files changed

+38
-21
lines changed

interfaces/sycl/Copy.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@
44

55
#include "SyclWrappedAPI.h"
66

7+
#include "Internals.h"
8+
79
#include <algorithm>
810
#include <math.h>
911

1012
using namespace device;
13+
using namespace device::internals;
1114

1215
void ConcreteAPI::copyTo(void *dst, const void *src, size_t size) {
1316
this->currentStatistics().explicitlyTransferredDataToDeviceBytes += size;
14-
this->currentDefaultQueue().submit([&](sycl::handler &cgh) { cgh.memcpy(dst, src, size); }).wait_and_throw();
17+
waitCheck(this->currentDefaultQueue().submit([&](sycl::handler &cgh) { cgh.memcpy(dst, src, size); }));
1518
}
1619

1720
void ConcreteAPI::copyFrom(void *dst, const void *src, size_t size) {
1821
this->currentStatistics().explicitlyTransferredDataToHostBytes += size;
19-
this->currentDefaultQueue().submit([&](sycl::handler &cgh) { cgh.memcpy(dst, src, size); }).wait_and_throw();
22+
waitCheck(this->currentDefaultQueue().submit([&](sycl::handler &cgh) { cgh.memcpy(dst, src, size); }));
2023
}
2124

2225
void ConcreteAPI::copyBetween(void *dst, const void *src, size_t size) {
23-
this->currentDefaultQueue().submit([&](sycl::handler &cgh) { cgh.memcpy(dst, src, size); }).wait_and_throw();
26+
waitCheck(this->currentDefaultQueue().submit([&](sycl::handler &cgh) { cgh.memcpy(dst, src, size); }));
2427
}
2528

2629
void ConcreteAPI::copy2dArrayTo(void *dst, size_t dpitch, const void *src, size_t spitch, size_t width, size_t height) {

interfaces/sycl/DeviceCircularQueueBuffer.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
#include "SyclWrappedAPI.h"
88
#include "utils/logger.h"
99

10+
#include "Internals.h"
11+
1012
#include <sycl/sycl.hpp>
1113

14+
using namespace device::internals;
15+
1216
namespace device {
1317

1418
// very inconvenient, but AdaptiveCpp doesn't allow much freedom when constructing a property_list
@@ -23,7 +27,7 @@ QueueWrapper::QueueWrapper(const sycl::device& dev, const std::function<void(syc
2327
}
2428

2529
void QueueWrapper::synchronize() {
26-
queue.wait_and_throw();
30+
waitCheck(queue);
2731
}
2832
void QueueWrapper::dependency(QueueWrapper& other) {
2933
// improvising... Adding an empty event here, mimicking a CUDA-like event dependency
@@ -130,7 +134,7 @@ void DeviceCircularQueueBuffer::joinQueueDepencency() {
130134
}
131135

132136
void DeviceCircularQueueBuffer::syncQueueWithHost(sycl::queue *queuePtr) {
133-
queuePtr->wait_and_throw();
137+
waitCheck(*queuePtr);
134138
}
135139

136140
void DeviceCircularQueueBuffer::syncAllQueuesWithHost() {
@@ -139,7 +143,7 @@ void DeviceCircularQueueBuffer::syncAllQueuesWithHost() {
139143
q.synchronize();
140144
}
141145
for (auto* q : this->externalQueues) {
142-
q->wait_and_throw();
146+
waitCheck(*q);
143147
}
144148
}
145149

interfaces/sycl/Events.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "SyclWrappedAPI.h"
66

7+
#include "Internals.h"
8+
79
#include <algorithm>
810
#include <cassert>
911
#include <optional>
@@ -13,6 +15,7 @@
1315
#endif // ONEAPI_UNDERHOOD
1416

1517
using namespace device;
18+
using namespace device::internals;
1619

1720
namespace {
1821
struct Event {
@@ -32,7 +35,7 @@ void ConcreteAPI::destroyEvent(void* eventPtr) {
3235
void ConcreteAPI::syncEventWithHost(void* eventPtr) {
3336
auto* event = static_cast<Event*>(eventPtr);
3437
if (event->syclEvent) {
35-
event->syclEvent.value().wait_and_throw();
38+
waitCheck(event->syclEvent.value());
3639
}
3740
}
3841

interfaces/sycl/Internals.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,25 @@
1010
#include <sycl/sycl.hpp>
1111
#include <string>
1212

13+
#include "utils/logger.h"
1314

1415
namespace device {
1516
namespace internals {
1617
constexpr static int DefaultBlockDim = 1024;
1718

19+
template<typename T>
20+
void waitCheck(T&& result) {
21+
try {
22+
std::forward<T>(result).wait_and_throw();
23+
}
24+
catch (const sycl::exception& exc) {
25+
logError() << "SYCL API error:" << std::string(exc.what());
26+
}
27+
catch (const std::exception& exc) {
28+
logError() << "SYCL API/C++ error:" << std::string(exc.what());
29+
}
30+
}
31+
1832
/*
1933
* Computes the execution range for a 1D range kernel given a target work group size and a total size.
2034
* The method determines how many work groups are needed to handle the total size given the local execution size

interfaces/sycl/Memory.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
#include "SyclWrappedAPI.h"
66
#include <iostream>
77

8+
#include "Internals.h"
9+
810
using namespace device;
11+
using namespace device::internals;
912

1013
void *ConcreteAPI::allocGlobMem(size_t size, bool compress) {
1114
auto *ptr = malloc_device(size, this->currentDefaultQueue());
1215
this->currentStatistics().allocatedMemBytes += size;
1316
this->currentMemoryToSizeMap().insert({ptr, size});
14-
this->currentDefaultQueue().wait();
17+
waitCheck(this->currentDefaultQueue());
1518
return ptr;
1619
}
1720

@@ -20,15 +23,15 @@ void *ConcreteAPI::allocUnifiedMem(size_t size, bool compress, Destination hint)
2023
this->currentStatistics().allocatedUnifiedMemBytes += size;
2124
this->currentStatistics().allocatedMemBytes += size;
2225
this->currentMemoryToSizeMap().insert({ptr, size});
23-
this->currentDefaultQueue().wait();
26+
waitCheck(this->currentDefaultQueue());
2427
return ptr;
2528
}
2629

2730
void *ConcreteAPI::allocPinnedMem(size_t size, bool compress, Destination hint) {
2831
auto *ptr = malloc_host(size, this->currentDefaultQueue());
2932
this->currentStatistics().allocatedMemBytes += size;
3033
this->currentMemoryToSizeMap().insert({ptr, size});
31-
this->currentDefaultQueue().wait();
34+
waitCheck(this->currentDefaultQueue());
3235
return ptr;
3336
}
3437

@@ -45,7 +48,7 @@ void ConcreteAPI::freeMem(void *devPtr) {
4548
this->currentStatistics().deallocatedMemBytes += this->currentMemoryToSizeMap().at(devPtr);
4649
this->currentMemoryToSizeMap().erase(devPtr);
4750
free(devPtr, this->currentDefaultQueue().get_context());
48-
this->currentDefaultQueue().wait();
51+
waitCheck(currentDefaultQueue());
4952
}
5053
}
5154

interfaces/sycl/SyclWrappedAPI.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,6 @@ class ConcreteAPI : public AbstractAPI {
174174

175175
void initDevices();
176176

177-
template<typename T>
178-
void waitCheck(T&& result) {
179-
try {
180-
std::forward<T>(result).wait_and_throw();
181-
}
182-
catch (const std::exception& exc) {
183-
logError() << "SYCL API error:" << std::string(exc.what());
184-
}
185-
}
186-
187177
std::string getCurrentDeviceInfoAsText();
188178
std::string getDeviceInfoAsTextInternal(sycl::device& dev);
189179

0 commit comments

Comments
 (0)