Skip to content

Commit

Permalink
Add custom GPU example
Browse files Browse the repository at this point in the history
  • Loading branch information
tobre1 committed Nov 13, 2024
1 parent 076cbc5 commit 71c8ebb
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 14 deletions.
9 changes: 8 additions & 1 deletion gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ add_dependencies(buildGPUApplication ViennaPS_GPU)

### EXAMPLES ###

# add_custom_target(buildGPUExamples)
add_custom_target(buildGPUExamples)

# add_executable(GPU_Trench ${embedded_SF6O2_pipeline}
# ${PROJECT_SOURCE_DIR}/examples/trench.cpp)
Expand All @@ -104,3 +104,10 @@ add_dependencies(buildGPUApplication ViennaPS_GPU)
# ${VIENNAPS_GPU_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/app)
# target_link_libraries(GPU_Hole ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY} ${VIENNAPS_LIBRARIES})
# add_dependencies(buildGPUExamples GPU_Hole)

add_executable(GPU_Custom ${embedded_SingleParticle_pipeline}
${PROJECT_SOURCE_DIR}/examples/custom.cpp)
target_include_directories(GPU_Custom PUBLIC ${OptiX_INCLUDE}
${VIENNAPS_GPU_INCLUDE_DIRS})
target_link_libraries(GPU_Custom ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY} ViennaPS)
add_dependencies(buildGPUExamples GPU_Custom)
66 changes: 66 additions & 0 deletions gpu/examples/custom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <geometries/psMakeTrench.hpp>
#include <psUtils.hpp>

// #include <psProcess.hpp>
// #include <pscuProcess.hpp>
#include <curtIndexMap.hpp>
#include <curtTracer.hpp>
#include <pscuProcessPipelines.hpp>

using namespace viennaps;

int main(int argc, char **argv) {

omp_set_num_threads(16);
constexpr int D = 3;
using NumericType = float;

gpu::Context context;
gpu::CreateContext(context);
Logger::setLogLevel(LogLevel::DEBUG);

const NumericType gridDelta = 1.;
const NumericType extent = 100.;
const NumericType trenchWidth = 15.;
const NumericType spacing = 20.;
const NumericType maskHeight = 40.;

const NumericType time = 3.;
const NumericType sticking = 1.0;
const NumericType exponent = 1000;
const int raysPerPoint = 3000;

auto domain = SmartPointer<Domain<NumericType, D>>::New();
MakeTrench<NumericType, D>(domain, gridDelta, extent, extent, trenchWidth,
maskHeight, 0., 0., false, true, Material::Si)
.apply();
domain->saveSurfaceMesh("trench_initial.vtp");

gpu::Particle<NumericType> particle{.name = "SingleParticle",
.sticking = sticking,
.cosineExponent = exponent};
particle.dataLabels.push_back("flux");

gpu::Tracer<NumericType, D> rayTrace(context, domain);
rayTrace.setPipeline(embedded_SingleParticle_pipeline);
rayTrace.setNumberOfRaysPerPoint(raysPerPoint);
rayTrace.setUseRandomSeed(false);
rayTrace.setPeriodicBoundary(false);
rayTrace.insertNextParticle(particle);
auto numRates = rayTrace.prepareParticlePrograms();
auto fluxesIndexMap = gpu::IndexMap(rayTrace.getParticles());

rayTrace.updateSurface(); // also creates mesh
auto numElements = rayTrace.getNumberOfElements();

rayTrace.apply();

auto mesh = rayTrace.getSurfaceMesh();
std::vector<NumericType> flux(numElements);
rayTrace.getFlux(flux.data(), 0, 0);

mesh->getCellData().insertNextScalarData(flux, "flux");

viennals::VTKWriter<NumericType>(mesh, "trench_flux.vtp").apply();
return 0;
}
9 changes: 3 additions & 6 deletions gpu/process/pscuProcess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ template <typename NumericType, int D> class Process {
return;
}
rayTrace.setPipeline(model->getPtxCode());
rayTrace.setLevelSet(domain);
rayTrace.setDomain(domain);
rayTrace.setNumberOfRaysPerPoint(raysPerPoint);
rayTrace.setUseRandomSeed(useRandomSeeds);
rayTrace.setPeriodicBoundary(periodicBoundary);
Expand Down Expand Up @@ -163,10 +163,7 @@ template <typename NumericType, int D> class Process {
const bool useCoverages = coverages != nullptr;

if (useCoverages) {
numCov = coverages->getScalarDataSize();
rayTrace.setUseCellData(numCov + 1); // + material IDs

Logger::getInstance().addInfo("Using coverages.").print();
meshddInfo("Using coverages.").print();

Timer timer;
Logger::getInstance().addInfo("Initializing coverages ... ").print();
Expand Down Expand Up @@ -606,7 +603,7 @@ template <typename NumericType, int D> class Process {
}

Context_t *context;
curtTracer<NumericType, D> rayTrace = curtTracer<NumericType, D>(context);
Tracer<NumericType, D> rayTrace = Tracer<NumericType, D>(context);

psDomainType domain = nullptr;
SmartPointer<ProcessModel<NumericType>> model = nullptr;
Expand Down
1 change: 0 additions & 1 deletion gpu/rayTracing/curtBoundary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <curtSBTRecords.hpp>
#include <curtUtilities.hpp>

#include <utGDT.hpp>
#include <vcVectorUtil.hpp>

// this can only get compiled if included in a cuda kernel
Expand Down
14 changes: 8 additions & 6 deletions gpu/rayTracing/curtTracer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <curtUtilities.hpp>

#include <utCudaBuffer.hpp>
#include <utGDT.hpp>
#include <utLaunchKernel.hpp>

namespace viennaps {
Expand All @@ -28,19 +27,19 @@ namespace gpu {

using namespace viennacore;

template <class T, int D> class curtTracer {
template <class T, int D> class Tracer {
using psDomainType = SmartPointer<::viennaps::Domain<T, D>>;

public:
/// constructor - performs all setup, including initializing
/// optix, creates module, pipeline, programs, SBT, etc.
curtTracer(Context passedContext, psDomainType passedDomain)
Tracer(Context passedContext, psDomainType passedDomain)
: context(passedContext), domain(passedDomain) {
initRayTracer();
mesh = SmartPointer<viennals::Mesh<float>>::New();
}

curtTracer(Context passedContext) : context(passedContext) {
Tracer(Context passedContext) : context(passedContext) {
initRayTracer();
mesh = SmartPointer<viennals::Mesh<float>>::New();
}
Expand All @@ -51,7 +50,7 @@ template <class T, int D> class curtTracer {

void setPipeline(char embeddedPtxCode[]) { ptxCode = embeddedPtxCode; }

void setLevelSet(psDomainType passedDomain) { domain = passedDomain; }
void setDomain(psDomainType passedDomain) { domain = passedDomain; }

void invalidateGeometry() { geometryValid = false; }

Expand Down Expand Up @@ -80,6 +79,9 @@ template <class T, int D> class curtTracer {
std::random_device rd;
std::uniform_int_distribution<unsigned int> gen;
launchParams.seed = gen(rd);
} else {
static int runNumber = 0;
launchParams.seed = runNumber++;
}

int numPointsPerDim =
Expand Down Expand Up @@ -130,7 +132,7 @@ template <class T, int D> class curtTracer {
// }
// delete temp;
// std::cout << "Time: " << diff.count() * 100 << " ms\n";
// std::cout << gdt::prettyDouble(numRays * particles.size()) << std::endl;
// std::cout << util::prettyDouble(numRays * particles.size()) << std::endl;
// std::cout << numRays << std::endl;

// sync - maybe remove in future
Expand Down

0 comments on commit 71c8ebb

Please sign in to comment.