OWL
Loading...
Searching...
No Matches
DeviceContext.h
1// ======================================================================== //
2// Copyright 2019-2021 Ingo Wald //
3// //
4// Licensed under the Apache License, Version 2.0 (the "License"); //
5// you may not use this file except in compliance with the License. //
6// You may obtain a copy of the License at //
7// //
8// http://www.apache.org/licenses/LICENSE-2.0 //
9// //
10// Unless required by applicable law or agreed to in writing, software //
11// distributed under the License is distributed on an "AS IS" BASIS, //
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
13// See the License for the specific language governing permissions and //
14// limitations under the License. //
15// ======================================================================== //
16
17#pragma once
18
19#include "owl/owl.h"
20#include "owl/common.h"
21#include "owl/DeviceMemory.h"
22#include "owl/helper/optix.h"
23
24namespace owl {
25
31 int alloc(size_t size);
32 void release(size_t begin, size_t size);
33 size_t maxAllocedID = 0;
34 private:
35 struct FreedRange {
36 size_t begin;
37 size_t size;
38 };
39 std::vector<FreedRange> freedRanges;
40 };
41
44 struct SBT {
45 size_t rayGenRecordCount = 0;
46 size_t rayGenRecordSize = 0;
47 DeviceMemory rayGenRecordsBuffer;
48
49 size_t hitGroupRecordSize = 0;
50 size_t hitGroupRecordCount = 0;
51 DeviceMemory hitGroupRecordsBuffer;
52
53 size_t missProgRecordSize = 0;
54 size_t missProgRecordCount = 0;
55 DeviceMemory missProgRecordsBuffer;
56
57 DeviceMemory launchParamsBuffer;
58 };
59
61 struct Context;
62
64 struct DeviceContext : public std::enable_shared_from_this<DeviceContext> {
65 typedef std::shared_ptr<DeviceContext> SP;
66
71 int owlID,
72 int cudaID);
74
76 std::string getDeviceName() const;
77
79 int getCudaDeviceID() const;
80
83 CUstream getStream() const { return stream; }
84
88 void configurePipelineOptions(bool debug = false);
89
90 void buildPrograms();
91 void buildMissPrograms();
92 void buildRayGenPrograms();
93 void buildHitGroupPrograms();
94
95 void destroyPrograms();
96 void destroyMissPrograms();
97 void destroyRayGenPrograms();
98 void destroyHitGroupPrograms();
99
100 void destroyPipeline();
101 void buildPipeline();
102
103 void buildCurvesModules();
104 void buildSphereModule();
105
109 std::vector<OptixProgramGroup> allActivePrograms;
110
111 OptixDeviceContext optixContext = nullptr;
112 CUcontext cudaContext = nullptr;
113 CUstream stream = nullptr;
114
115 OptixPipelineCompileOptions pipelineCompileOptions = {};
116 OptixPipelineLinkOptions pipelineLinkOptions = {};
117 OptixModuleCompileOptions moduleCompileOptions = {};
118 OptixPipeline pipeline = nullptr;
119 SBT sbt = {};
120
123 OptixModule curvesModule[2][3]
124 = {
125 { nullptr, nullptr, nullptr },
126 { nullptr, nullptr, nullptr }
127 };
128
130 OptixModule spheresModule = nullptr;
131
134
138 const int ID;
139
140 /* the cuda device ID that this logical device runs on */
141 const int cudaDeviceID;
142 };
143
148 std::vector<DeviceContext::SP> createDeviceContexts(Context *parent,
149 int32_t *requestedDeviceIDs,
150 int numRequestedDevices);
151
157 inline SetActiveGPU(const DeviceContext::SP &device)
158 {
159 OWL_CUDA_CHECK(cudaGetDevice(&savedActiveDeviceID));
160 OWL_CUDA_CHECK(cudaSetDevice(device->cudaDeviceID));
161 }
162 inline SetActiveGPU(const DeviceContext *device)
163 {
164 OWL_CUDA_CHECK(cudaGetDevice(&savedActiveDeviceID));
165 OWL_CUDA_CHECK(cudaSetDevice(device->cudaDeviceID));
166 }
167 inline ~SetActiveGPU()
168 {
169 OWL_CUDA_CHECK_NOTHROW(cudaSetDevice(savedActiveDeviceID));
170 }
171 private:
172 int savedActiveDeviceID = -1;
173 };
174
175} // ::owl
176
Definition: Context.h:32
Definition: DeviceContext.h:64
int getCudaDeviceID() const
Definition: DeviceContext.cpp:241
void configurePipelineOptions(bool debug=false)
Definition: DeviceContext.cpp:257
OptixModule spheresModule
Definition: DeviceContext.h:130
const int ID
Definition: DeviceContext.h:138
std::vector< OptixProgramGroup > allActivePrograms
Definition: DeviceContext.h:109
void buildMissPrograms()
Definition: DeviceContext.cpp:477
OptixModule curvesModule[2][3]
Definition: DeviceContext.h:124
std::string getDeviceName() const
Definition: DeviceContext.cpp:233
CUstream getStream() const
Definition: DeviceContext.h:83
Context *const parent
Definition: DeviceContext.h:133
Definition: DeviceMemory.h:23
Definition: DeviceContext.h:30
int alloc(size_t size)
Definition: DeviceContext.cpp:53
void release(size_t begin, size_t size)
Definition: DeviceContext.cpp:76
Definition: DeviceContext.h:44
Definition: DeviceContext.h:156