|
6 | 6 |
|
7 | 7 | #include <cstring>
|
8 | 8 |
|
| 9 | +#include "flamegpu/runtime/detail/SharedBlock.h" |
| 10 | + |
9 | 11 | namespace flamegpu {
|
10 | 12 | namespace exception {
|
11 | 13 |
|
@@ -81,20 +83,20 @@ class DeviceException {
|
81 | 83 | */
|
82 | 84 | template<typename... Args>
|
83 | 85 | __device__ void setMessage(const char *format, Args... args) {
|
84 |
| - extern __shared__ DeviceExceptionBuffer* buff[]; |
| 86 | + using detail::sm; |
85 | 87 | // Only the thread which first reported error gets to output
|
86 | 88 | if (hasError) {
|
87 | 89 | // Only output once
|
88 |
| - if (buff[2]->format_string[0]) |
| 90 | + if (sm()->device_exception->format_string[0]) |
89 | 91 | return;
|
90 | 92 | // Copy the format string
|
91 | 93 | unsigned int eos = 0;
|
92 | 94 | for (eos = 0; eos < DeviceExceptionBuffer::FORMAT_BUFF_LEN; ++eos)
|
93 | 95 | if (format[eos] == '\0')
|
94 | 96 | break;
|
95 |
| - memcpy(buff[2]->format_string, format, eos * sizeof(char)); |
| 97 | + memcpy(sm()->device_exception->format_string, format, eos * sizeof(char)); |
96 | 98 | // Process args
|
97 |
| - subformat_recurse(buff[2], args...); |
| 99 | + subformat_recurse(sm()->device_exception, args...); |
98 | 100 | }
|
99 | 101 | }
|
100 | 102 |
|
@@ -135,18 +137,18 @@ class DeviceException {
|
135 | 137 | */
|
136 | 138 | __device__ DeviceException(const char *file, const unsigned int line)
|
137 | 139 | : hasError(!getErrorCount()) {
|
138 |
| - extern __shared__ DeviceExceptionBuffer* buff[]; |
| 140 | + using detail::sm; |
139 | 141 | if (hasError) {
|
140 | 142 | // Copy file location
|
141 | 143 | const size_t file_len = strlen(file);
|
142 |
| - memcpy(buff[2]->file_path, file, file_len); |
| 144 | + memcpy(sm()->device_exception->file_path, file, file_len); |
143 | 145 | // Copy line no
|
144 |
| - buff[2]->line_no = line; |
| 146 | + sm()->device_exception->line_no = line; |
145 | 147 | // Copy block/thread indices
|
146 | 148 | const uint3 bid3 = blockIdx;
|
147 |
| - memcpy(buff[2]->block_id, &bid3, sizeof(unsigned int) * 3); |
| 149 | + memcpy(sm()->device_exception->block_id, &bid3, sizeof(unsigned int) * 3); |
148 | 150 | const uint3 tid3 = threadIdx;
|
149 |
| - memcpy(buff[2]->thread_id, &tid3, sizeof(unsigned int) * 3); |
| 151 | + memcpy(sm()->device_exception->thread_id, &tid3, sizeof(unsigned int) * 3); |
150 | 152 | }
|
151 | 153 | }
|
152 | 154 | /**
|
@@ -188,9 +190,9 @@ __device__ inline void DeviceException::subformat(DeviceExceptionBuffer *buff, c
|
188 | 190 | }
|
189 | 191 | }
|
190 | 192 | __device__ unsigned int DeviceException::getErrorCount() {
|
191 |
| - extern __shared__ DeviceExceptionBuffer* buff[]; |
| 193 | + using detail::sm; |
192 | 194 | // Are we the first exception
|
193 |
| - return atomicInc(&buff[2]->error_count, UINT_MAX); |
| 195 | + return atomicInc(&sm()->device_exception->error_count, UINT_MAX); |
194 | 196 | }
|
195 | 197 | #endif
|
196 | 198 | #else
|
|
0 commit comments