MCPcopy Create free account
hub / github.com/a2flo/floor / cuda_buffer

Method cuda_buffer

src/device/cuda/cuda_buffer.cpp:39–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37// TODO: proper error (return) value handling everywhere
38
39cuda_buffer::cuda_buffer(const device_queue& cqueue,
40 const size_t& size_,
41 std::span<uint8_t> host_data_,
42 const MEMORY_FLAG flags_,
43 device_buffer* shared_buffer_) :
44device_buffer(cqueue, size_, host_data_, flags_, shared_buffer_) {
45 if(size < min_multiple()) return;
46
47 switch(flags & MEMORY_FLAG::READ_WRITE) {
48 case MEMORY_FLAG::READ:
49 case MEMORY_FLAG::WRITE:
50 case MEMORY_FLAG::READ_WRITE:
51 // no special handling for cuda
52 break;
53 // all possible cases handled
54 default: floor_unreachable();
55 }
56
57 switch(flags & MEMORY_FLAG::HOST_READ_WRITE) {
58 case MEMORY_FLAG::HOST_READ:
59 case MEMORY_FLAG::HOST_WRITE:
60 case MEMORY_FLAG::NONE:
61 // no special handling for cuda
62 break;
63 case MEMORY_FLAG::HOST_READ_WRITE:
64 // both - this is the default
65 break;
66 // all possible cases handled
67 default: floor_unreachable();
68 }
69
70 // TODO: handle the remaining flags + host ptr
71
72 // need to allocate the buffer on the correct device, if a context was specified,
73 // else: assume the correct context is already active
74 const auto& cuda_dev = (const cuda_device&)cqueue.get_device();
75 if (cuda_dev.ctx != nullptr) {
76 if (!cuda_dev.make_context_current()) {
77 throw std::runtime_error("failed to make CUDA context current for buffer allocation");
78 }
79 }
80
81 // check Vulkan buffer sharing validity
82 if (has_flag<MEMORY_FLAG::VULKAN_SHARING>(flags)) {
83#if defined(FLOOR_NO_VULKAN)
84 log_error("Vulkan support is not enabled");
85 return;
86#else
87 if (!cuda_can_use_external_memory()) {
88 log_error("can't use Vulkan buffer sharing, because use of external memory is not supported");
89 return;
90 }
91#endif
92 }
93
94 // actually create the buffer
95 if(!create_internal(true, cqueue)) {
96 return; // can't do much else

Callers

nothing calls this directly

Calls 3

get_deviceMethod · 0.80
make_context_currentMethod · 0.80

Tested by

no test coverage detected