Skip to content

MAX_KERNEL_NUM_VARIABLES module-attribute

MAX_KERNEL_NUM_VARIABLES = 64

BruteforceGPUSampler

Bases: Sampler

parameters property

parameters: Dict[str, Any]

properties property

properties: Dict[str, Any]

sample

sample(bqm, num_states, suffix_size, grid_size, block_size, num_steps_per_kernel=16, partial_diff_buffer_depth=1, dtype=np.float32)

Solve Binary Quadratic Model using exhaustive (bruteforce) search on the GPU.

Parameters:

Name Type Description Default
bqm

Binary Quadratic Model instance to solve.

required
num_states

number of lowest energy states to compute.

required
suffix_size

exponent l such that 2 ** l is the number of configurations kept in the GPU working set at a time; the search sweeps 2 ** (N - l) such chunks, where N is the number of variables of bqm.

required
grid_size

number of blocks for the custom kernels. Note that this parameter does not affect the grid on which the Thrust kernels are launched.

required
block_size

number of threads per block for custom kernels. Note that this parameter does not affect the grid on which the Thrust kernels are launched.

required
num_steps_per_kernel

number of chunks processed by a single kernel launch.

16
partial_diff_buffer_depth

depth of the incremental energy difference buffers.

1
dtype

datatype to use, either np.float32 or np.float64, or one of the names accepted by :func:normalize_dtype (in particular "float" means single precision). The default is np.float32, which on most GPUs is significantly faster than 64-bit floating point numbers. For num_states == 1, the GPU backend automatically enables compensated updates and periodic numeric re-anchoring when using np.float32 on large models (at least 40 variables) to remove drift from long chains of incremental energy updates. Note that np.float64 is therefore a different numerical path, not merely a slower one.

float32

Returns:

Type Description

sample set containing num_states samples.

Raises:

Type Description
ValueError

if dtype is not a supported precision, or if the problem size and suffix_size are not enumerable by the kernels (see :func:validate_kernel_problem_size).

normalize_dtype

normalize_dtype(dtype) -> type

Resolve a user-supplied dtype specification to np.float32 or np.float64.

Parameters:

Name Type Description Default
dtype

either one of np.float32/np.float64 (or an equivalent NumPy dtype object), or one of the names "float", "float32", "single", "double", "float64". Note that "float" means single precision here, matching the --dtype choices of the command line interface, and deliberately not NumPy's interpretation of the same string.

required

Returns:

Type Description
type

np.float32 or np.float64.

Raises:

Type Description
ValueError

if the specification does not denote a supported precision.

validate_kernel_problem_size

validate_kernel_problem_size(num_variables: int, suffix_size: int) -> None

Check that a problem of given size can be enumerated by the CUDA kernels.

The kernels keep each configuration in a single 64-bit word and iterate over 2 ** (num_variables - suffix_size) chunks of 2 ** suffix_size configurations, so both bounds have to hold before any kernel is launched. Violating them would otherwise produce silently truncated or wrong results rather than an error.

Parameters:

Name Type Description Default
num_variables int

number of variables handed to the kernel.

required
suffix_size int

number of variables forming the resident enumeration chunk.

required

Raises:

Type Description
ValueError

if the problem is too wide, or the suffix does not fit in it.