Skip to content

Commit 9c68066

Browse files
committed
refacter DeviceType
1 parent ffb47fe commit 9c68066

File tree

4 files changed

+41
-37
lines changed

4 files changed

+41
-37
lines changed

Intern/rayx-core/src/Shader/LightSources/EnergyDistributions/EnergyDistribution.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ struct EnergyDistributionList {
1616
};
1717

1818
struct EnergyDistributionDataBase {
19-
using HardEdge = rayx::HardEdge;
20-
using SoftEdge = rayx::SoftEdge;
21-
using SeparateEnergies = rayx::SeparateEnergies;
19+
using HardEdge = rayx::HardEdge;
20+
using SoftEdge = rayx::SoftEdge;
21+
using SeparateEnergies = rayx::SeparateEnergies;
2222
using EnergyDistributionList = rayx::EnergyDistributionList;
2323
};
2424

25-
using EnergyDistributionDataVariant = Variant<EnergyDistributionDataBase, EnergyDistributionDataBase::HardEdge, EnergyDistributionDataBase::SoftEdge, SeparateEnergies, EnergyDistributionDataBase::EnergyDistributionList>;
25+
using EnergyDistributionDataVariant = Variant<EnergyDistributionDataBase, EnergyDistributionDataBase::HardEdge, EnergyDistributionDataBase::SoftEdge,
26+
SeparateEnergies, EnergyDistributionDataBase::EnergyDistributionList>;
2627

2728
RAYX_FN_ACC double selectEnergy(const HardEdge& __restrict hardEdge, Rand& __restrict rand);
2829
RAYX_FN_ACC double selectEnergy(const SoftEdge& __restrict softEdge, Rand& __restrict rand);

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

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ DeviceType platformToDeviceType();
2020

2121
template <>
2222
DeviceType platformToDeviceType<alpaka::PlatformCpu>() {
23-
return DeviceType::Cpu;
23+
#if defined(RAYX_OPENMP_ENABLED)
24+
return DeviceType::CpuParallel;
25+
#else
26+
return DeviceType::CpuSerial;
27+
#endif
2428
}
2529

2630
#if defined(RAYX_CUDA_ENABLED)
@@ -30,13 +34,6 @@ DeviceType platformToDeviceType<alpaka::PlatformCudaRt>() {
3034
}
3135
#endif
3236

33-
#if defined(RAYX_HIP_ENABLED)
34-
template <>
35-
DeviceType platformToDeviceType<alpaka::PlatformHipRt>() {
36-
return DeviceType::GpuHip;
37-
}
38-
#endif
39-
4037
template <typename AccTag>
4138
std::vector<Device> getAvailableDevicesProps() {
4239
std::vector<Device> devices;
@@ -80,31 +77,26 @@ std::vector<Device> getAvailableDevices(DeviceType deviceType = DeviceType::All)
8077
};
8178

8279
#if defined(RAYX_OPENMP_ENABLED)
83-
using TagCpu = alpaka::TagCpuOmp2Blocks;
80+
if (deviceType & DeviceType::CpuParallel) append(alpaka::TagCpuOmp2Blocks{});
8481
#else
85-
using TagCpu = alpaka::TagCpuSerial;
82+
if (deviceType & DeviceType::CpuSerial) append(alpaka::TagCpuSerial{});
8683
#endif
87-
if (deviceType & DeviceType::Cpu) append(TagCpu{});
8884

8985
#if defined(RAYX_CUDA_ENABLED)
9086
if (deviceType & DeviceType::GpuCuda) append(alpaka::TagGpuCudaRt{});
9187
#endif
9288

93-
#if defined(RAYX_HIP_ENABLED)
94-
if (deviceType & DeviceType::GpuHip) append(alpaka::TagGpuHipRt{});
95-
#endif
96-
9789
return devices;
9890
}
9991

10092
std::string deviceTypeToString(DeviceType deviceType) {
10193
std::vector<const char*> names;
10294

103-
if (deviceType & DeviceType::Cpu) names.push_back("Cpu");
95+
if (deviceType & DeviceType::CpuSerial) names.push_back("CpuSerial");
96+
if (deviceType & DeviceType::CpuParallel) names.push_back("CpuParallel");
10497
if (deviceType & DeviceType::GpuCuda) names.push_back("GpuCuda");
105-
if (deviceType & DeviceType::GpuHip) names.push_back("GpuHip");
10698

107-
if (names.empty()) names.push_back("Unsupported");
99+
if (names.empty()) names.push_back("None");
108100

109101
std::stringstream ss;
110102

@@ -131,9 +123,8 @@ void DeviceConfig::dumpDevices() const {
131123
RAYX_LOG << "Device - index: " << i << ", type: " << deviceTypeToString(device.type) << ", name: " << device.name;
132124
}
133125

134-
#if !defined(RAYX_CUDA_ENABLED) && !defined(RAYX_HIP_ENABLED)
135-
if (m_fetchedDeviceType != DeviceType::Cpu)
136-
RAYX_WARN << "No GPU support was compiled in this build.";
126+
#if !defined(RAYX_CUDA_ENABLED)
127+
if (!(m_fetchedDeviceType & DeviceType::Cpu)) RAYX_WARN << "GPU support is not enabled in this build.";
137128
#endif
138129
}
139130

@@ -197,4 +188,20 @@ DeviceConfig& DeviceConfig::enableBestDevice(DeviceType deviceType) {
197188
return *this;
198189
}
199190

191+
DeviceConfig::DeviceType DeviceConfig::availableDeviceTypes() {
192+
DeviceType deviceType = DeviceType::None;
193+
194+
#if defined(RAYX_OPENMP_ENABLED)
195+
deviceType = static_cast<DeviceType>(deviceType | DeviceType::CpuParallel);
196+
#else
197+
deviceType = static_cast<DeviceType>(deviceType | DeviceType::CpuSerial);
198+
#endif
199+
200+
#if defined(RAYX_CUDA_ENABLED)
201+
deviceType = static_cast<DeviceType>(deviceType | DeviceType::GpuCuda);
202+
#endif
203+
204+
return deviceType;
205+
}
206+
200207
} // namespace rayx

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ namespace rayx {
99

1010
struct RAYX_API DeviceConfig {
1111
enum RAYX_API DeviceType {
12-
Unsupported = 0,
13-
Cpu = 1 << 0,
14-
GpuCuda = 1 << 1,
15-
GpuHip = 1 << 2,
16-
Gpu = GpuCuda | GpuHip,
12+
None = 0,
13+
CpuSerial = 1 << 0,
14+
CpuParallel = 1 << 1,
15+
Cpu = CpuSerial | CpuParallel,
16+
GpuCuda = 1 << 2,
17+
Gpu = GpuCuda,
1718
All = Cpu | Gpu,
1819
};
1920

@@ -46,6 +47,8 @@ struct RAYX_API DeviceConfig {
4647

4748
DeviceConfig& enableBestDevice(DeviceType deviceType = DeviceType::All);
4849

50+
static DeviceType availableDeviceTypes();
51+
4952
std::vector<Device> devices;
5053

5154
private:

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ inline std::shared_ptr<rayx::DeviceTracer> createDeviceTracer(DeviceType deviceT
1717
#else
1818
RAYX_EXIT << "Failed to create Tracer with Cuda device. Cuda was disabled during build.";
1919
return nullptr;
20-
#endif
21-
case DeviceType::GpuHip:
22-
#if defined(RAYX_HIP_ENABLED)
23-
eturn std::make_shared<rayx::MegaKernelTracer<alpaka::TagGpuHipRt>>(deviceIndex);
24-
#else
25-
RAYX_EXIT << "Failed to create Tracer with Hip device. Hip was disabled during build.";
26-
return nullptr;
2720
#endif
2821
default: // case DeviceType::Cpu
2922
#if defined(RAYX_OPENMP_ENABLED)

0 commit comments

Comments
 (0)