-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add foundational CUDA support and basic kernel #459
Draft
corybarr
wants to merge
23
commits into
main
Choose a base branch
from
add-cuda
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
08421f2
check in partially completed, need kernel to continue
corybarr a0bcc4e
fix merge conflict
corybarr 1289ce1
add stub of CudaManager.h
corybarr 2cc510b
Revert "Remove cuda from build. No longer needed for Kit 105"
lilleyse 7dbbc2b
Fix all compilation errors
corybarr 6477098
Merge branch 'main' of github.com:CesiumGS/cesium-omniverse into add-…
corybarr b06bbb1
update extern/CMakeLists.txt
corybarr d5546b2
add nvrtc and cuda to CMakeLists.txt
corybarr 1c3c770
manually revert commit 34e6e3ff6917ef59d2786540fe4a5ac6f5e9f7f6
corybarr c844568
add in tileId
corybarr ab04c1f
enable basic print-to-screen kernel
corybarr 18422c3
run placeholder kernel for every tile
corybarr 0324bd4
merge with add-cuda-cmake
corybarr 3e37801
remove cudart from CMakeLists.txt
corybarr 643f76d
delete CudaRunners when tile is freed
corybarr f0ec135
clang formatting fixes
corybarr 701b60b
cosmetic
corybarr f8a62f5
clean up CudaManager.h
corybarr 8313f49
clean up CudaManager
corybarr 39a702d
fix variable shadowing
corybarr 49b897e
remove redundant lines in CMakeLists.txt
866ee66
Merge branch 'add-cuda-cmake' into add-cuda
corybarr f08be11
Revert "Temporarily remove nvrtc and nvrtc-builtins from install"
lilleyse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
namespace cesium::omniverse::cudaKernels { | ||
|
||
inline const char* printPointsKernel = R"( | ||
|
||
extern "C" __global__ void printPoints(float3** points, int numPoints) { | ||
const size_t i = blockIdx.x * blockDim.x + threadIdx.x; | ||
if (i >= numPoints) return; | ||
|
||
int pointIndex = static_cast<int>(i); | ||
|
||
printf("point %d: %f, %f, %f\n", pointIndex, points[0][pointIndex].x, points[0][pointIndex].y, points[0][pointIndex].z); | ||
} | ||
)"; | ||
|
||
inline const char* helloWorldKernel = R"( | ||
extern "C" __global__ | ||
void helloWorld(double* values, size_t count) | ||
{ | ||
size_t i = blockIdx.x * blockDim.x + threadIdx.x; | ||
if (count <= i) return; | ||
|
||
printf("Hello world, from index %llu\n", i); | ||
} | ||
)"; | ||
|
||
inline const char* createVoxelsKernel = R"( | ||
extern "C" __global__ | ||
void createVoxels(float3** points, size_t count) | ||
{ | ||
size_t i = blockIdx.x * blockDim.x + threadIdx.x; | ||
if (count <= i) return; | ||
|
||
// printf("Placeholder: create voxel at index %llu\n", i); | ||
} | ||
)"; | ||
} // namespace cesium::omniverse::cudaKernels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#pragma once | ||
|
||
#include "cesium/omniverse/CudaKernels.h" | ||
#include "cesium/omniverse/CudaManager.h" | ||
|
||
#include <cuda/include/cuda.h> | ||
#include <cuda/include/cuda_runtime.h> | ||
#include <cuda/include/nvrtc.h> | ||
#include <omni/fabric/FabricUSD.h> | ||
#include <omni/fabric/IFabric.h> | ||
|
||
#include <any> | ||
#include <stdexcept> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace cesium::omniverse { | ||
class CudaManager; | ||
class CudaRunner; | ||
struct CudaKernel; | ||
struct CudaKernelArgs; | ||
|
||
enum CudaKernelType { HELLO_WORLD, CREATE_VOXELS, PRINT_POINTS }; | ||
enum CudaUpdateType { ONCE, ON_UPDATE_FRAME }; | ||
|
||
struct CudaKernelArgs { | ||
std::unordered_map<std::string, std::any> args; | ||
}; | ||
|
||
struct CudaKernel { | ||
nvrtcProgram program; | ||
char* ptx; | ||
CUmodule module; | ||
CUfunction function; | ||
}; | ||
|
||
class CudaRunner { | ||
public: | ||
CudaKernelType kernelType; | ||
|
||
CudaRunner() = delete; | ||
CudaRunner( | ||
CudaKernelType cudaKernelType, | ||
CudaUpdateType updateType, | ||
int64_t tileId, | ||
CudaKernelArgs args, | ||
int elementCountArg) | ||
: kernelType(cudaKernelType) | ||
, kernelArgs(std::move(args)) | ||
, elementCount(elementCountArg) | ||
, _tileId(tileId) | ||
, _updateType(updateType){}; | ||
[[nodiscard]] int64_t getTileId() const { | ||
return _tileId; | ||
} | ||
CudaKernelArgs kernelArgs; | ||
[[nodiscard]] const CudaUpdateType& getUpdateType() const { | ||
return _updateType; | ||
} | ||
int elementCount; | ||
|
||
private: | ||
// omni::fabric::PrimBucketList _bucketList; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Placeholder for incorporating the kernel args in the next PR. |
||
int64_t _tileId; | ||
CudaUpdateType _updateType; | ||
}; | ||
|
||
class CudaManager { | ||
public: | ||
static CudaManager& getInstance() { | ||
static CudaManager instance; | ||
return instance; | ||
} | ||
|
||
void onUpdateFrame(); | ||
void addRunner(CudaRunner& cudaRunner); | ||
void removeRunner(int64_t tileId); | ||
[[nodiscard]] const char* getKernelCode(CudaKernelType kernelType) const; | ||
[[nodiscard]] const char* getFunctionName(CudaKernelType kernelType) const; | ||
|
||
private: | ||
CUdevice _device; | ||
CUcontext _context; | ||
bool _initialized = false; | ||
std::unordered_map<CudaUpdateType, std::unordered_map<int64_t, CudaRunner>> _runnersByUpdateType; | ||
std::unordered_map<CudaKernelType, CudaKernel> _kernels; | ||
int _blockSize, _numBlocks; | ||
|
||
void compileKernel(CudaKernelType kernelType); | ||
void runAllRunners(); | ||
void initialize(); | ||
void runRunner(CudaRunner& runner); | ||
void** packArgs(CudaKernelArgs cudaKernelArgs, CudaKernelType cudaKernelType); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Placeholder for next PR. Signature might change. |
||
}; | ||
} // namespace cesium::omniverse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clang convention of starting with a comma seems odd. Is this correct?