Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-12 08:27:08

0001 #include <cstdlib>
0002 #include <cstdio>
0003 
0004 #include <cuda_runtime.h>
0005 
0006 #include "CSGOptiXHelpers.h"
0007 
0008 namespace
0009 {
0010     void require(bool condition, const char* expression, int line)
0011     {
0012         if (condition) return;
0013         std::fprintf(stderr, "%s:%d requirement failed: %s\n", __FILE__, line, expression);
0014         std::exit(EXIT_FAILURE);
0015     }
0016 }
0017 
0018 #define REQUIRE(expression) require((expression), #expression, __LINE__)
0019 
0020 struct CSGOptiXHelpersTestResult
0021 {
0022     bool torch_carries_matline;
0023     bool frame_carries_matline;
0024     bool cerenkov_carries_matline;
0025     bool scintillation_carries_matline;
0026     bool modified_cerenkov_carries_matline;
0027     float entering_distance;
0028     float exiting_distance;
0029     float non_simulation_exit_distance;
0030 };
0031 
0032 __global__ void CSGOptiXHelpersTest_kernel(CSGOptiXHelpersTestResult* result)
0033 {
0034     result->torch_carries_matline =
0035         CSGOptiX7_GenstepCarriesMaterialLine(OpticksGenstep_TORCH);
0036     result->frame_carries_matline =
0037         CSGOptiX7_GenstepCarriesMaterialLine(OpticksGenstep_FRAME);
0038     result->cerenkov_carries_matline =
0039         CSGOptiX7_GenstepCarriesMaterialLine(OpticksGenstep_CERENKOV);
0040     result->scintillation_carries_matline =
0041         CSGOptiX7_GenstepCarriesMaterialLine(OpticksGenstep_SCINTILLATION);
0042     result->modified_cerenkov_carries_matline =
0043         CSGOptiX7_GenstepCarriesMaterialLine(OpticksGenstep_G4Cerenkov_modified);
0044 
0045     const float coincident_distance = 10.f;
0046     result->entering_distance = CSGOptiX7_ReportedIntersectionDistance(
0047         coincident_distance,
0048         SRG_SIMULATE,
0049         -1.f);
0050     result->exiting_distance = CSGOptiX7_ReportedIntersectionDistance(
0051         coincident_distance,
0052         SRG_SIMULATE,
0053         1.f);
0054     result->non_simulation_exit_distance = CSGOptiX7_ReportedIntersectionDistance(
0055         coincident_distance,
0056         SRG_SIMTRACE,
0057         1.f);
0058 }
0059 
0060 int main()
0061 {
0062     CSGOptiXHelpersTestResult* device_result = nullptr;
0063     REQUIRE(cudaMalloc(&device_result, sizeof(CSGOptiXHelpersTestResult)) == cudaSuccess);
0064 
0065     CSGOptiXHelpersTest_kernel<<<1, 1>>>(device_result);
0066     REQUIRE(cudaGetLastError() == cudaSuccess);
0067     REQUIRE(cudaDeviceSynchronize() == cudaSuccess);
0068 
0069     CSGOptiXHelpersTestResult result = {};
0070     REQUIRE(cudaMemcpy(
0071         &result,
0072         device_result,
0073         sizeof(CSGOptiXHelpersTestResult),
0074         cudaMemcpyDeviceToHost) == cudaSuccess);
0075     REQUIRE(cudaFree(device_result) == cudaSuccess);
0076 
0077     REQUIRE(!result.torch_carries_matline);
0078     REQUIRE(!result.frame_carries_matline);
0079     REQUIRE(result.cerenkov_carries_matline);
0080     REQUIRE(result.scintillation_carries_matline);
0081     REQUIRE(result.modified_cerenkov_carries_matline);
0082 
0083     REQUIRE(result.entering_distance == 10.f);
0084     REQUIRE(result.exiting_distance == nextafterf(10.f, INFINITY));
0085     REQUIRE(result.entering_distance < result.exiting_distance);
0086     REQUIRE(result.non_simulation_exit_distance == 10.f);
0087 
0088     std::puts("CSGOptiXHelpersTest: PASS");
0089     return 0;
0090 }
0091 
0092 #undef REQUIRE