Module Cuda.Module

A CUDA module type represents CUDA code that's ready to execute, i.e. is loaded. See: Module Management.

type jit_target =
  1. | COMPUTE_30
  2. | COMPUTE_32
  3. | COMPUTE_35
  4. | COMPUTE_37
  5. | COMPUTE_50
  6. | COMPUTE_52
  7. | COMPUTE_53
  8. | COMPUTE_60
  9. | COMPUTE_61
  10. | COMPUTE_62
  11. | COMPUTE_70
  12. | COMPUTE_72
  13. | COMPUTE_75
  14. | COMPUTE_80
  15. | COMPUTE_86
  16. | COMPUTE_87
  17. | COMPUTE_89
  18. | COMPUTE_90
  19. | COMPUTE_90A
    (*

    Compute device class 9.0 with accelerated features.

    *)

Compute device classes. See enum CUjit_target.

val sexp_of_jit_target : jit_target -> Sexplib0.Sexp.t
type jit_fallback =
  1. | PREFER_PTX
  2. | PREFER_BINARY

Cubin matching fallback strategies. See CUjit_fallback.

val sexp_of_jit_fallback : jit_fallback -> Sexplib0.Sexp.t
type jit_cache_mode =
  1. | NONE
  2. | CG
    (*

    Compile with L1 cache disabled.

    *)
  3. | CA
    (*

    Compile with L1 cache enabled.

    *)

Caching modes for dlcm. See CUjit_cacheMode.

val sexp_of_jit_cache_mode : jit_cache_mode -> Sexplib0.Sexp.t
type jit_option =
  1. | MAX_REGISTERS of int
    (*

    Max number of registers that a thread may use.

    *)
  2. | THREADS_PER_BLOCK of int
    (*

    Specifies minimum number of threads per block to target compilation for or returns the number of threads the compiler actually targeted. Cannot be combined with TARGET.

    *)
  3. | WALL_TIME of {
    1. milliseconds : float;
    }
  4. | INFO_LOG_BUFFER of bigstring
  5. | ERROR_LOG_BUFFER of bigstring
  6. | OPTIMIZATION_LEVEL of int
    (*

    0 to 4, with 4 being the default and highest level of optimizations.

    *)
  7. | TARGET_FROM_CUCONTEXT
  8. | TARGET of jit_target
  9. | FALLBACK_STRATEGY of jit_fallback
  10. | GENERATE_DEBUG_INFO of bool
    (*

    Helpful for cuda-gdb.

    *)
  11. | LOG_VERBOSE of bool
  12. | GENERATE_LINE_INFO of bool
    (*

    Helpful for cuda-gdb.

    *)
  13. | CACHE_MODE of jit_cache_mode
  14. | POSITION_INDEPENDENT_CODE of bool
val sexp_of_jit_option : jit_option -> Sexplib0.Sexp.t
type func
type t
val load_data_ex : Nvrtc.compile_to_ptx_result -> jit_option list -> t

Currently, the image passed via this call is the PTX source. See cuModuleLoadDataEx.

The module is finalized using cuModuleUnload. The finalizer captures the context when load_data_ex is called to temporarily push it on the stack for unloading.

val get_function : t -> name:string -> func

The returned function retains the module, so the module is not finalized (unloaded) while the function is still in use. See cuModuleGetFunction.

val get_global : t -> name:string -> Deviceptr.t * Unsigned.size_t
type occupancy_flag =
  1. | DISABLE_CACHING_OVERRIDE
    (*

    On platforms where global caching affects occupancy, the calculator's default behavior is to fall back to computing as if caching were disabled when caching is on but the per-block resource usage would leave zero occupancy. This flag suppresses that fallback, so such a configuration reports 0.

    *)

How the occupancy calculator handles special cases; the empty flag list is CU_OCCUPANCY_DEFAULT. See CUoccupancy_flags.

val sexp_of_occupancy_flag : occupancy_flag -> Sexplib0.Sexp.t
val max_active_blocks_per_multiprocessor : ?dynamic_smem_bytes:int -> ?flags:occupancy_flag list -> func -> block_size:int -> int

The maximum number of blocks of block_size threads that can be simultaneously resident on one multiprocessor, given the kernel's register and shared memory usage. dynamic_smem_bytes (default 0) is the per-block dynamic shared memory the launch would request, i.e. the shared_mem_bytes of Stream.launch_kernel. The result is 0 for a configuration that cannot be launched at all -- one asking for more shared memory or more threads per block than the device provides -- rather than an error.

The theoretical occupancy of such a launch -- the fraction of a multiprocessor's warp slots that are filled -- is float (result * warps_per_block) /. float max_warps, where warps_per_block = (block_size + device_props.warp_size - 1) / device_props.warp_size and max_warps = device_props.max_threads_per_multiprocessor / device_props.warp_size. The hardware allocates whole warps, so a block of 33 threads takes two warp slots rather than 33 thread slots; the two formulations coincide when block_size is a multiple of the warp size. result * device_props.multiprocessor_count blocks are enough to fill the whole device. See cuOccupancyMaxActiveBlocksPerMultiprocessor, and with a non-empty flags (default []) cuOccupancyMaxActiveBlocksPerMultiprocessorWithFlags.

type suggested_launch_config = {
  1. min_grid_size : int;
    (*

    Grid size, in blocks, that achieves the maximum occupancy.

    *)
  2. block_size : int;
    (*

    Block size, in threads, that achieves the maximum occupancy.

    *)
}

The launch configuration suggested by suggested_launch_config.

val sexp_of_suggested_launch_config : suggested_launch_config -> Sexplib0.Sexp.t
val suggested_launch_config : ?dynamic_smem_bytes:int -> ?block_size_limit:int -> ?flags:occupancy_flag list -> func -> suggested_launch_config

A block size that achieves the kernel's maximum occupancy -- more precisely, the maximum number of active warps with the fewest blocks per multiprocessor -- together with the minimum grid size that achieves that occupancy. Where max_active_blocks_per_multiprocessor scores a block size you picked, this picks one for you; the two agree in that max_active_blocks_per_multiprocessor func ~block_size at the suggested block_size times device_props.multiprocessor_count is the returned min_grid_size.

dynamic_smem_bytes (default 0) is a per-block dynamic shared memory request that does not vary with the block size -- the driver also accepts a block-size-to-shared-memory callback, which this binding does not expose. block_size_limit (default 0, meaning the maximum the device and the kernel permit) caps the block size considered, for a kernel that is only correct up to some number of threads. Always calls cuOccupancyMaxPotentialBlockSizeWithFlags, of which cuOccupancyMaxPotentialBlockSize is the empty-flags case.