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

Method cuda_buffer

compute/cuda/cuda_buffer.cpp:38–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36// TODO: proper error (return) value handling everywhere
37
38cuda_buffer::cuda_buffer(const compute_queue& cqueue,
39 const size_t& size_,
40 std::span<uint8_t> host_data_,
41 const COMPUTE_MEMORY_FLAG flags_,
42 const uint32_t opengl_type_,
43 const uint32_t external_gl_object_,
44 compute_buffer* shared_buffer_) :
45compute_buffer(cqueue, size_, host_data_, flags_, opengl_type_, external_gl_object_, shared_buffer_) {
46 if(size < min_multiple()) return;
47
48 switch(flags & COMPUTE_MEMORY_FLAG::READ_WRITE) {
49 case COMPUTE_MEMORY_FLAG::READ:
50 case COMPUTE_MEMORY_FLAG::WRITE:
51 case COMPUTE_MEMORY_FLAG::READ_WRITE:
52 // no special handling for cuda
53 break;
54 // all possible cases handled
55 default: floor_unreachable();
56 }
57
58 switch(flags & COMPUTE_MEMORY_FLAG::HOST_READ_WRITE) {
59 case COMPUTE_MEMORY_FLAG::HOST_READ:
60 case COMPUTE_MEMORY_FLAG::HOST_WRITE:
61 case COMPUTE_MEMORY_FLAG::NONE:
62 // no special handling for cuda
63 break;
64 case COMPUTE_MEMORY_FLAG::HOST_READ_WRITE:
65 // both - this is the default
66 break;
67 // all possible cases handled
68 default: floor_unreachable();
69 }
70
71 // TODO: handle the remaining flags + host ptr
72
73 // need to allocate the buffer on the correct device, if a context was specified,
74 // else: assume the correct context is already active
75 const auto& cuda_dev = (const cuda_device&)cqueue.get_device();
76 if(cuda_dev.ctx != nullptr) {
77 CU_CALL_RET(cu_ctx_set_current(cuda_dev.ctx),
78 "failed to make cuda context current")
79 }
80
81 // check Vulkan buffer sharing validity
82 if (has_flag<COMPUTE_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)) {

Callers

nothing calls this directly

Calls 2

get_deviceMethod · 0.80

Tested by

no test coverage detected