batchlas::ScopedEnvVar Class Reference

Overview

Sets (or unsets) an environment variable for a scope and restores it on exit.

Both the constructor and the destructor call detail::reload_settings(), so the library sees the pinned value immediately and stops seeing it when the scope ends. A raw ::setenv is invisible to batchlas::settings(); use this instead.

{
ScopedEnvVar pin("BATCHLAS_GEMM_ROUTE", "native");
gemm(ctx, a, b, c, GemmOptions<float>{}); // runs the native kernel
}
ScopedEnvVar(const char *name, const char *value)
Pin name to value for the scope.
Definition env.hh:110
Event gemm(Queue &ctx, const MatrixView< T, MatrixFormat::Dense > &A, const MatrixView< T, MatrixFormat::Dense > &B, const MatrixView< T, MatrixFormat::Dense > &C, T alpha, T beta, Transpose transA, Transpose transB, ComputePrecision precision=ComputePrecision::Default)
Batched general matrix-matrix multiply.
Options for gemm(): .
Definition options.hh:144
Precondition
name outlives the object (in practice a string literal); it is borrowed, not copied.
Warning
Not thread-safe, because the process environment is not: construct from a test body or benchmark setup, never inside a parallel region. Do not let one straddle a *_buffer_size() query and its solve.
See also
Environment variables

Definition at line 104 of file env.hh.

#include <batchlas/util/env.hh>

Constructors

◆ ScopedEnvVar() [1/2]

batchlas::ScopedEnvVar::ScopedEnvVar ( const char * name,
const char * value )
inline

Pin name to value for the scope.

Parameters
namethe variable's name
valuethe value to set, or nullptr to unset the variable for the duration (which asks for the automatic route regardless of the surrounding environment)

Definition at line 110 of file env.hh.

◆ ~ScopedEnvVar()

batchlas::ScopedEnvVar::~ScopedEnvVar ( )
inline

Restore the previous value (or unset state) and reload the settings.

Definition at line 124 of file env.hh.

◆ ScopedEnvVar() [2/2]

batchlas::ScopedEnvVar::ScopedEnvVar ( const ScopedEnvVar & )
delete

Functions

◆ operator=()

ScopedEnvVar & batchlas::ScopedEnvVar::operator= ( const ScopedEnvVar & )
delete