Skip to content

Commit 5c5e056

Browse files
Atraxusichinii
authored andcommitted
Actually moving data to device, not sure its correct
1 parent d9170fa commit 5c5e056

File tree

15 files changed

+533
-27
lines changed

15 files changed

+533
-27
lines changed

Intern/rayx-core/src/RaySoA.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ RaySoA bundleHistoryToRaySoA(const BundleHistory& bundle) {
3333
BundleHistory raySoAToBundleHistory(const RaySoA& rays) {
3434
RAYX_PROFILE_FUNCTION_STDOUT();
3535

36-
auto bundle = BundleHistory(rays.num_paths);
36+
if (rays.num_events == 0) return BundleHistory();
37+
int maxPathId = *std::max_element(rays.path_id.begin(), rays.path_id.end());
38+
auto bundle = BundleHistory(maxPathId + 1);
3739

3840
for (int i = 0; i < rays.num_events; ++i) {
3941
const auto path_id = rays.path_id[i];

Intern/rayx-core/src/Shader/DynamicElements.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void dynamicElements(const int gid, const InvState& inv, OutputEvents& outputEve
6060
}
6161

6262
// write ray in local element coordinates to global memory
63-
if (!inv.recordMask || inv.recordMask[col.elementIndex]) {
63+
if (numRecorded < inv.maxEvents && (!inv.recordMask || inv.recordMask[col.elementIndex])) {
6464
outputEvents.events[gid * inv.maxEvents + numRecorded] = ray;
6565
++numRecorded;
6666
}

Intern/rayx-core/src/Shader/EventType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ inline std::string findEventTypeString(const EventType eventType) {
5959
case EventType::Emitted:
6060
return "Emitted";
6161
default:
62-
_debug_throw("unable to convert EventType (%d) to string!", static_cast<int>(eventType));
62+
//_debug_throw("unable to convert EventType (%d) to string!", static_cast<int>(eventType));
6363
return "<unknown-event-type>";
6464
}
6565
}

Intern/rayx-core/src/Tracer/DeviceTracer.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
namespace RAYX {
1111

12+
// Small helper to make passing the full record mask easier.
13+
inline std::vector<bool> fullRecordMask(size_t numElements) {
14+
return std::vector<bool>(numElements, true);
15+
}
16+
1217
/**
1318
* @brief DeviceTracer is an interface to a tracer implementation
1419
* we use this interface to remove the actual implementation from the rayx api
@@ -17,8 +22,13 @@ class RAYX_API DeviceTracer {
1722
public:
1823
virtual ~DeviceTracer() = default;
1924

20-
virtual RaySoA trace(const Group&, Sequential sequential, const int maxBatchSize, const int maxEvents, std::shared_ptr<bool[]> recordMask,
21-
const RayAttrFlag attr) = 0;
25+
virtual RaySoA trace(
26+
const Group& beamline,
27+
Sequential sequential,
28+
const int maxBatchSize,
29+
const int maxEvents,
30+
const std::vector<bool>& recordMask,
31+
const RayAttrFlag attr) = 0;
2232
};
2333

2434
} // namespace RAYX

Intern/rayx-core/src/Tracer/MegaKernelTracer.h

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ struct Resources {
4343
// resources per beamline. constant per beamline
4444
/// beamline elements
4545
Buf<OpticalElement> d_elements;
46+
/// mask for which elements to record events
47+
Buf<bool> d_recordMask;
4648
/// all rays generated from all light sources
4749
std::vector<Ray> h_rays;
4850

@@ -75,7 +77,7 @@ struct Resources {
7577

7678
/// update resources
7779
template <typename Queue>
78-
Config update(Queue q, const Group& group, int maxEvents, int maxBatchSize) {
80+
Config update(Queue q, const Group& group, int maxEvents, int maxBatchSize, const std::vector<bool>& recordMask) {
7981
RAYX_PROFILE_FUNCTION_STDOUT();
8082

8183
const auto platformHost = alpaka::PlatformCpu{};
@@ -98,6 +100,16 @@ struct Resources {
98100
allocBuf(q, d_elements, numElements);
99101
alpaka::memcpy(q, *d_elements, alpaka::createView(devHost, elements, numElements));
100102

103+
// record mask
104+
assert(recordMask.size() == static_cast<size_t>(numElements));
105+
allocBuf(q, d_recordMask, numElements);
106+
std::unique_ptr<bool[]> tmpHostMask(new bool[numElements]);
107+
for(int i = 0; i < numElements; ++i) {
108+
tmpHostMask[i] = recordMask[i];
109+
}
110+
auto hostView = alpaka::createView(devHost, tmpHostMask.get(), numElements);
111+
alpaka::memcpy(q, *d_recordMask, hostView);
112+
101113
// input rays
102114
h_rays = group.compileSources(1); // TODO: generate rays on device
103115
const auto numRaysTotal = static_cast<int>(h_rays.size());
@@ -149,8 +161,13 @@ class MegaKernelTracer : public DeviceTracer {
149161
Resources<Acc> m_resources;
150162

151163
public:
152-
virtual RaySoA trace(const Group& beamline, const Sequential sequential, const int maxBatchSize, const int maxEvents,
153-
std::shared_ptr<bool[]> recordMask, const RayAttrFlag attr) override {
164+
virtual RaySoA trace(
165+
const Group& beamline,
166+
Sequential sequential,
167+
const int maxBatchSize,
168+
const int maxEvents,
169+
const std::vector<bool>& recordMask,
170+
const RayAttrFlag attr) override {
154171
RAYX_PROFILE_FUNCTION_STDOUT();
155172

156173
const auto platformHost = alpaka::PlatformCpu{};
@@ -160,7 +177,7 @@ class MegaKernelTracer : public DeviceTracer {
160177
using Queue = alpaka::Queue<Acc, alpaka::Blocking>;
161178
auto q = Queue(devAcc);
162179

163-
const auto conf = m_resources.update(q, beamline, maxEvents, maxBatchSize);
180+
const auto conf = m_resources.update(q, beamline, maxEvents, maxBatchSize, recordMask);
164181
const auto randomSeed = randomDouble();
165182

166183
RAYX_VERB << "tracing beamline:";
@@ -199,9 +216,8 @@ class MegaKernelTracer : public DeviceTracer {
199216
alpaka::memcpy(q, *m_resources.d_rays, raysViewBatch);
200217

201218
// trace current batch
202-
traceBatch(devAcc, q, conf.numElements, conf.numRaysTotal, batchSize, batchStartRayIndex, maxEvents, recordMask, randomSeed, sequential);
219+
traceBatch(devAcc, q, conf.numElements, conf.numRaysTotal, batchSize, batchStartRayIndex, maxEvents, randomSeed, sequential);
203220

204-
// prefix sum on compactEventCounts to get compactEventOffsets
205221
alpaka::memcpy(q, alpaka::createView(devHost, compactEventCounts, batchSize), *m_resources.d_compactEventCounts, batchSize);
206222
std::exclusive_scan(compactEventCounts.begin(), compactEventCounts.begin() + batchSize, compactEventOffsets.begin(), 0);
207223
alpaka::memcpy(q, *m_resources.d_compactEventOffsets, alpaka::createView(devHost, compactEventOffsets, batchSize), batchSize);
@@ -259,7 +275,7 @@ class MegaKernelTracer : public DeviceTracer {
259275
private:
260276
template <typename DevAcc, typename Queue>
261277
void traceBatch(DevAcc devAcc, Queue q, int numElements, int numRaysTotal, int batchSize, int batchStartRayIndex, int maxEvents,
262-
std::shared_ptr<bool[]> recordMask, double randomSeed, Sequential sequential) {
278+
double randomSeed, Sequential sequential) {
263279
RAYX_PROFILE_FUNCTION_STDOUT();
264280

265281
// inputs
@@ -277,7 +293,7 @@ class MegaKernelTracer : public DeviceTracer {
277293
.numElements = numElements,
278294
.materialIndices = alpaka::getPtrNative(*m_resources.d_materialIndices),
279295
.materialTables = alpaka::getPtrNative(*m_resources.d_materialTable),
280-
.recordMask = recordMask.get(),
296+
.recordMask = alpaka::getPtrNative(*m_resources.d_recordMask),
281297
.rays = alpaka::getPtrNative(*m_resources.d_rays),
282298
};
283299

Intern/rayx-core/src/Tracer/Tracer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ Tracer::Tracer(const DeviceConfig& deviceConfig) {
5151
}
5252
}
5353

54-
RaySoA Tracer::trace(const Group& group, Sequential sequential, uint64_t maxBatchSize, uint32_t maxEvents, std::shared_ptr<bool[]> recordMask,
55-
RayAttrFlag attr) {
54+
RaySoA Tracer::trace(const Group& group, Sequential sequential, uint64_t maxBatchSize, uint32_t maxEvents, const std::vector<bool>& recordMask, const RayAttrFlag attr) {
5655
// in sequential tracing, maxEvents should be equal to the number of elements
5756
if (sequential == Sequential::Yes) maxEvents = group.numElements();
5857

Intern/rayx-core/src/Tracer/Tracer.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ class RAYX_API Tracer {
2929
// This will call the trace implementation of a subclass
3030
// See `BundleHistory` for information about the return value.
3131
// `max_batch_size` corresponds to the maximal number of rays that will be put into `traceRaw` in one batch.
32-
RaySoA trace(const Group& group, Sequential sequential, uint64_t maxBatchSize, uint32_t maxEvents, std::shared_ptr<bool[]> recordMask = nullptr,
33-
RayAttrFlag attr = RayAttrFlag::All);
32+
33+
RaySoA trace(
34+
const Group& group,
35+
const Sequential sequential,
36+
uint64_t maxBatchSize,
37+
uint32_t maxEvents,
38+
const std::vector<bool>& recordMask,
39+
const RayAttrFlag attr = RayAttrFlag::All);
3440

3541
static int defaultMaxEvents(const Group* group);
3642

-33.3 KB
Binary file not shown.
-8.24 MB
Binary file not shown.
-33.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)