pub struct CurrentContext;
Expand description

Type representing the top context in the thread-local stack.

Implementations§

Returns the preferred cache configuration for the current context.

On devices where the L1 cache and shared memory use the same hardware resources, this function returns the preferred cache configuration for the current context. For devices where the size of the L1 cache and shared memory are fixed, this will always return CacheConfig::PreferNone.

Example:
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();
let cache_config = CurrentContext::get_cache_config().unwrap();

Return the device ID for the current context.

Example:
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();
let device = CurrentContext::get_device().unwrap();

Return the context flags for the current context.

Example:
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();
let flags = CurrentContext::get_flags().unwrap();

Return resource limits for the current context.

Example:
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();
let stack_size = CurrentContext::get_resource_limit(ResourceLimit::StackSize).unwrap();

Return resource limits for the current context.

Example:
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();
let stack_size = CurrentContext::get_resource_limit(ResourceLimit::StackSize).unwrap();

Return the least and greatest stream priorities.

If the program attempts to create a stream with a priority outside of this range, it will be automatically clamped to within the valid range. If the device does not support stream priorities, the returned range will contain zeroes.

Example:
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();
let priority_range = CurrentContext::get_stream_priority_range().unwrap();

Sets the preferred cache configuration for the current context.

On devices where L1 cache and shared memory use the same hardware resources, this sets the preferred cache configuration for the current context. This is only a preference. The driver will use the requested configuration if possible, but is free to choose a different configuration if required to execute the function.

This setting does nothing on devices where the size of the L1 cache and shared memory are fixed.

Example:
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();
CurrentContext::set_cache_config(CacheConfig::PreferL1).unwrap();

Sets a requested resource limit for the current context.

Note that this is only a request; the driver is free to modify the requested value to meet hardware requirements. Each limit has some specific restrictions.

  • StackSize: Controls the stack size in bytes for each GPU thread
  • PrintfFifoSize: Controls the size in bytes of the FIFO used by the printf() device system call. This cannot be changed after a kernel has been launched which uses the printf() function.
  • MallocHeapSize: Controls the size in bytes of the heap used by the malloc() and free() device system calls. This cannot be changed aftr a kernel has been launched which uses the malloc() and free() system calls.
  • DeviceRuntimeSyncDepth: Controls the maximum nesting depth of a grid at which a thread can safely call cudaDeviceSynchronize(). This cannot be changed after a kernel has been launched which uses the device runtime. When setting this limit, keep in mind that additional levels of sync depth require the driver to reserve large amounts of device memory which can no longer be used for device allocations.
  • DeviceRuntimePendingLaunchCount: Controls the maximum number of outstanding device runtime launches that can be made from the current context. A grid is outstanding from the point of the launch up until the grid is known to have completed. Keep in mind that increasing this limit will require the driver to reserve larger amounts of device memory which can no longer be used for device allocations.
  • MaxL2FetchGranularity: Controls the L2 fetch granularity. This is purely a performance hint and it can be ignored or clamped depending on the platform.
Example:
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();
CurrentContext::set_resource_limit(ResourceLimit::StackSize, 2048).unwrap();

Sets the preferred shared memory configuration for the current context.

On devices with configurable shared memory banks, this function will set the context’s shared memory bank size which is used for subsequent kernel launches.

Example:
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();
CurrentContext::set_shared_memory_config(SharedMemoryConfig::DefaultBankSize).unwrap();

Returns a non-owning handle to the current context.

Example:
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();
let unowned = CurrentContext::get_current().unwrap();

Set the given context as the current context for this thread.

If there is no context set for this thread, this pushes the given context onto the stack. If there is a context set for this thread, this replaces the top context on the stack with the given context.

Example:
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();
CurrentContext::set_current(&context).unwrap();

Block for a context’s tasks to complete

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.