MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / from_descriptor

Method from_descriptor

crates/cust/src/memory/array.rs:317–481  ·  view source on GitHub ↗

Constructs a generic ArrayObject from an `ArrayDescriptor`.

(descriptor: &ArrayDescriptor)

Source from the content-addressed store, hash-verified

315
316 /// Constructs a generic ArrayObject from an `ArrayDescriptor`.
317 pub fn from_descriptor(descriptor: &ArrayDescriptor) -> CudaResult<Self> {
318 // We validate the descriptor up front in debug mode. This provides a good error message to
319 // the user when they get something wrong, but doesn't re-validate in release mode.
320 if cfg!(debug_assertions) {
321 assert_ne!(
322 0,
323 descriptor.width(),
324 "Cannot allocate an array with 0 Width"
325 );
326
327 if !descriptor.flags().contains(ArrayObjectFlags::LAYERED) && descriptor.depth() > 0 {
328 assert_ne!(
329 0,
330 descriptor.height(),
331 "If Depth is non-zero and the descriptor is not LAYERED, then Height must also \
332 be non-zero."
333 );
334 }
335
336 if descriptor.flags().contains(ArrayObjectFlags::CUBEMAP) {
337 assert_eq!(
338 descriptor.height(),
339 descriptor.width(),
340 "Height and Width must be equal for CUBEMAP arrays."
341 );
342
343 if descriptor.flags().contains(ArrayObjectFlags::LAYERED) {
344 assert_eq!(
345 0,
346 descriptor.depth() % 6,
347 "Depth must be a multiple of 6 when the array descriptor is for a LAYERED \
348 CUBEMAP."
349 );
350 } else {
351 assert_eq!(
352 6,
353 descriptor.depth(),
354 "Depth must be equal to 6 when the array descriptor is for a CUBEMAP."
355 );
356 }
357 }
358
359 assert!(
360 descriptor.num_channels() == 1
361 || descriptor.num_channels() == 2
362 || descriptor.num_channels() == 4,
363 "NumChannels was set to {}. It must be 1, 2, or 4.",
364 descriptor.num_channels()
365 );
366
367 // Exhaustively check bounds of arrays
368 let device = CurrentContext::get_device()?;
369
370 let attr = |attr| Ok(1..=(device.get_attribute(attr)? as usize));
371
372 let (description, bounds) = if descriptor.flags().contains(ArrayObjectFlags::CUBEMAP) {
373 if descriptor.flags().contains(ArrayObjectFlags::LAYERED) {
374 (

Callers

nothing calls this directly

Calls 8

depthMethod · 0.80
containsMethod · 0.45
flagsMethod · 0.45
get_attributeMethod · 0.45
heightMethod · 0.45
widthMethod · 0.45
to_resultMethod · 0.45
as_mut_ptrMethod · 0.45

Tested by

no test coverage detected