Halide
Halide::Target Struct Reference

A struct representing a target machine and os to generate code for. More...

#include <Target.h>

Public Types

enum  OS {
  OSUnknown = 0, Linux, Windows, OSX,
  Android, IOS, QuRT, NoOS
}
 The operating system used by the target. More...
 
enum  Arch {
  ArchUnknown = 0, X86, ARM, MIPS,
  Hexagon, POWERPC
}
 The architecture used by the target. More...
 
enum  Feature {
  JIT = halide_target_feature_jit, Debug = halide_target_feature_debug, NoAsserts = halide_target_feature_no_asserts, NoBoundsQuery = halide_target_feature_no_bounds_query,
  SSE41 = halide_target_feature_sse41, AVX = halide_target_feature_avx, AVX2 = halide_target_feature_avx2, FMA = halide_target_feature_fma,
  FMA4 = halide_target_feature_fma4, F16C = halide_target_feature_f16c, ARMv7s = halide_target_feature_armv7s, NoNEON = halide_target_feature_no_neon,
  VSX = halide_target_feature_vsx, POWER_ARCH_2_07 = halide_target_feature_power_arch_2_07, CUDA = halide_target_feature_cuda, CUDACapability30 = halide_target_feature_cuda_capability30,
  CUDACapability32 = halide_target_feature_cuda_capability32, CUDACapability35 = halide_target_feature_cuda_capability35, CUDACapability50 = halide_target_feature_cuda_capability50, CUDACapability61 = halide_target_feature_cuda_capability61,
  OpenCL = halide_target_feature_opencl, CLDoubles = halide_target_feature_cl_doubles, OpenGL = halide_target_feature_opengl, OpenGLCompute = halide_target_feature_openglcompute,
  UserContext = halide_target_feature_user_context, Matlab = halide_target_feature_matlab, Profile = halide_target_feature_profile, NoRuntime = halide_target_feature_no_runtime,
  Metal = halide_target_feature_metal, MinGW = halide_target_feature_mingw, CPlusPlusMangling = halide_target_feature_c_plus_plus_mangling, LargeBuffers = halide_target_feature_large_buffers,
  HVX_64 = halide_target_feature_hvx_64, HVX_128 = halide_target_feature_hvx_128, HVX_v62 = halide_target_feature_hvx_v62, HVX_v65 = halide_target_feature_hvx_v65,
  HVX_v66 = halide_target_feature_hvx_v66, HVX_shared_object = halide_target_feature_hvx_use_shared_object, FuzzFloatStores = halide_target_feature_fuzz_float_stores, SoftFloatABI = halide_target_feature_soft_float_abi,
  MSAN = halide_target_feature_msan, AVX512 = halide_target_feature_avx512, AVX512_KNL = halide_target_feature_avx512_knl, AVX512_Skylake = halide_target_feature_avx512_skylake,
  AVX512_Cannonlake = halide_target_feature_avx512_cannonlake, TraceLoads = halide_target_feature_trace_loads, TraceStores = halide_target_feature_trace_stores, TraceRealizations = halide_target_feature_trace_realizations,
  FeatureEnd = halide_target_feature_end
}
 Optional features a target can have. More...
 

Public Member Functions

 Target ()
 
 Target (OS o, Arch a, int b, std::vector< Feature > initial_features=std::vector< Feature >())
 
void set_feature (Feature f, bool value=true)
 
void set_features (std::vector< Feature > features_to_set, bool value=true)
 
bool has_feature (Feature f) const
 
bool features_any_of (std::vector< Feature > test_features) const
 
bool features_all_of (std::vector< Feature > test_features) const
 
Target with_feature (Feature f) const
 Return a copy of the target with the given feature set. More...
 
Target without_feature (Feature f) const
 Return a copy of the target with the given feature cleared. More...
 
bool has_gpu_feature () const
 Is a fully feature GPU compute runtime enabled? I.e. More...
 
bool supports_type (const Type &t) const
 Does this target allow using a certain type. More...
 
EXPORT bool supports_type (const Type &t, DeviceAPI device) const
 Does this target allow using a certain type on a certain device. More...
 
EXPORT bool supports_device_api (DeviceAPI api) const
 Returns whether a particular device API can be used with this Target. More...
 
bool operator== (const Target &other) const
 
bool operator!= (const Target &other) const
 
EXPORT std::string to_string () const
 Convert the Target into a string form that can be reconstituted by merge_string(), which will always be of the form. More...
 
int natural_vector_size (Halide::Type t) const
 Given a data type, return an estimate of the "natural" vector size for that data type when compiling for this Target. More...
 
template<typename data_t >
int natural_vector_size () const
 Given a data type, return an estimate of the "natural" vector size for that data type when compiling for this Target. More...
 
bool has_large_buffers () const
 Return true iff 64 bits and has_feature(LargeBuffers). More...
 
int64_t maximum_buffer_size () const
 Return the maximum buffer size in bytes supported on this Target. More...
 
EXPORT bool supported () const
 Was libHalide compiled with support for this target? More...
 
EXPORT Target (const std::string &s)
 Given a string of the form used in HL_TARGET (e.g. More...
 
EXPORT Target (const char *s)
 Given a string of the form used in HL_TARGET (e.g. More...
 

Static Public Member Functions

static EXPORT bool validate_target_string (const std::string &s)
 Check if a target string is valid. More...
 

Public Attributes

enum Halide::Target::OS os
 
enum Halide::Target::Arch arch
 
int bits
 The bit-width of the target machine. More...
 

Detailed Description

A struct representing a target machine and os to generate code for.

Examples:
tutorial/lesson_11_cross_compilation.cpp, and tutorial/lesson_12_using_the_gpu.cpp.

Definition at line 21 of file Target.h.

Member Enumeration Documentation

◆ OS

The operating system used by the target.

Determines which system calls to generate. Corresponds to os_name_map in Target.cpp.

Enumerator
OSUnknown 
Linux 
Windows 
OSX 
Android 
IOS 
QuRT 
NoOS 

Definition at line 25 of file Target.h.

◆ Arch

The architecture used by the target.

Determines the instruction set to use. Corresponds to arch_name_map in Target.cpp.

Enumerator
ArchUnknown 
X86 
ARM 
MIPS 
Hexagon 
POWERPC 

Definition at line 30 of file Target.h.

◆ Feature

Optional features a target can have.

Corresponds to feature_name_map in Target.cpp. See definitions in HalideRuntime.h for full information.

Enumerator
JIT 
Debug 
NoAsserts 
NoBoundsQuery 
SSE41 
AVX 
AVX2 
FMA 
FMA4 
F16C 
ARMv7s 
NoNEON 
VSX 
POWER_ARCH_2_07 
CUDA 
CUDACapability30 
CUDACapability32 
CUDACapability35 
CUDACapability50 
CUDACapability61 
OpenCL 
CLDoubles 
OpenGL 
OpenGLCompute 
UserContext 
Matlab 
Profile 
NoRuntime 
Metal 
MinGW 
CPlusPlusMangling 
LargeBuffers 
HVX_64 
HVX_128 
HVX_v62 
HVX_v65 
HVX_v66 
HVX_shared_object 
FuzzFloatStores 
SoftFloatABI 
MSAN 
AVX512 
AVX512_KNL 
AVX512_Skylake 
AVX512_Cannonlake 
TraceLoads 
TraceStores 
TraceRealizations 
FeatureEnd 

Definition at line 39 of file Target.h.

Constructor & Destructor Documentation

◆ Target() [1/4]

Halide::Target::Target ( )
inline

Definition at line 90 of file Target.h.

Referenced by Target().

◆ Target() [2/4]

Halide::Target::Target ( OS  o,
Arch  a,
int  b,
std::vector< Feature initial_features = std::vector<Feature>() 
)
inline

Definition at line 91 of file Target.h.

References EXPORT, set_feature(), Target(), and validate_target_string().

◆ Target() [3/4]

EXPORT Halide::Target::Target ( const std::string &  s)
explicit

Given a string of the form used in HL_TARGET (e.g.

"x86-64-avx"), construct the Target it specifies. Note that this always starts with the result of get_host_target(), replacing only the parts found in the target string, so if you omit (say) an OS specification, the host OS will be used instead. An empty string is exactly equivalent to get_host_target().

Invalid target strings will fail with a user_error.

◆ Target() [4/4]

EXPORT Halide::Target::Target ( const char *  s)
explicit

Given a string of the form used in HL_TARGET (e.g.

"x86-64-avx"), construct the Target it specifies. Note that this always starts with the result of get_host_target(), replacing only the parts found in the target string, so if you omit (say) an OS specification, the host OS will be used instead. An empty string is exactly equivalent to get_host_target().

Invalid target strings will fail with a user_error.

Member Function Documentation

◆ validate_target_string()

static EXPORT bool Halide::Target::validate_target_string ( const std::string &  s)
static

Check if a target string is valid.

Referenced by Target().

◆ set_feature()

void Halide::Target::set_feature ( Feature  f,
bool  value = true 
)
inline
Examples:
tutorial/lesson_12_using_the_gpu.cpp.

Definition at line 116 of file Target.h.

References FeatureEnd, and user_assert.

Referenced by set_features(), Target(), with_feature(), and without_feature().

◆ set_features()

void Halide::Target::set_features ( std::vector< Feature features_to_set,
bool  value = true 
)
inline
Examples:
tutorial/lesson_11_cross_compilation.cpp.

Definition at line 122 of file Target.h.

References set_feature().

◆ has_feature()

◆ features_any_of()

bool Halide::Target::features_any_of ( std::vector< Feature test_features) const
inline

Definition at line 134 of file Target.h.

References has_feature().

◆ features_all_of()

bool Halide::Target::features_all_of ( std::vector< Feature test_features) const
inline

Definition at line 143 of file Target.h.

References has_feature().

◆ with_feature()

Target Halide::Target::with_feature ( Feature  f) const
inline

Return a copy of the target with the given feature set.

This is convenient when enabling certain features (e.g. NoBoundsQuery) in an initialization list, where the target to be mutated may be a const reference.

Definition at line 156 of file Target.h.

References set_feature().

◆ without_feature()

Target Halide::Target::without_feature ( Feature  f) const
inline

Return a copy of the target with the given feature cleared.

This is convenient when disabling certain features (e.g. NoBoundsQuery) in an initialization list, where the target to be mutated may be a const reference.

Definition at line 166 of file Target.h.

References set_feature().

◆ has_gpu_feature()

bool Halide::Target::has_gpu_feature ( ) const
inline

Is a fully feature GPU compute runtime enabled? I.e.

is Func::gpu_tile and similar going to work? Currently includes CUDA, OpenCL, and Metal. We do not include OpenGL, because it is not capable of gpgpu, and is not scheduled via Func::gpu_tile. TODO: Should OpenGLCompute be included here?

Definition at line 178 of file Target.h.

References CUDA, has_feature(), Metal, and OpenCL.

Referenced by Halide::Internal::schedule_scalar().

◆ supports_type() [1/2]

bool Halide::Target::supports_type ( const Type t) const
inline

Does this target allow using a certain type.

Generally all types except 64-bit float and int/uint should be supported by all backends.

It is likely better to call the version below which takes a DeviceAPI.

Definition at line 188 of file Target.h.

References Halide::Type::bits(), CLDoubles, EXPORT, has_feature(), Halide::Type::is_float(), Metal, OpenCL, and supports_device_api().

◆ supports_type() [2/2]

EXPORT bool Halide::Target::supports_type ( const Type t,
DeviceAPI  device 
) const

Does this target allow using a certain type on a certain device.

This is the prefered version of this routine.

◆ supports_device_api()

EXPORT bool Halide::Target::supports_device_api ( DeviceAPI  api) const

Returns whether a particular device API can be used with this Target.

Referenced by supports_type().

◆ operator==()

bool Halide::Target::operator== ( const Target other) const
inline

Definition at line 209 of file Target.h.

References arch, bits, and os.

◆ operator!=()

bool Halide::Target::operator!= ( const Target other) const
inline

Definition at line 216 of file Target.h.

References EXPORT, and to_string().

◆ to_string()

EXPORT std::string Halide::Target::to_string ( ) const

Convert the Target into a string form that can be reconstituted by merge_string(), which will always be of the form.

arch-bits-os-feature1-feature2...featureN.

Note that is guaranteed that Target(t1.to_string()) == t1, but not that Target(s).to_string() == s (since there can be multiple strings that parse to the same Target)... unless t1 contains 'unknown' fields (in which case you'll get a string that can't be parsed, which is intentional).

Referenced by operator!=().

◆ natural_vector_size() [1/2]

int Halide::Target::natural_vector_size ( Halide::Type  t) const
inline

Given a data type, return an estimate of the "natural" vector size for that data type when compiling for this Target.

Definition at line 235 of file Target.h.

References ArchUnknown, AVX, AVX2, AVX512, AVX512_Cannonlake, AVX512_KNL, AVX512_Skylake, Halide::Type::bytes(), has_feature(), Hexagon, HVX_128, HVX_64, Halide::Type::is_float(), Halide::Type::is_int(), Halide::Type::is_uint(), OSUnknown, user_assert, user_error, and X86.

◆ natural_vector_size() [2/2]

template<typename data_t >
int Halide::Target::natural_vector_size ( ) const
inline

Given a data type, return an estimate of the "natural" vector size for that data type when compiling for this Target.

Definition at line 288 of file Target.h.

◆ has_large_buffers()

bool Halide::Target::has_large_buffers ( ) const
inline

Return true iff 64 bits and has_feature(LargeBuffers).

Definition at line 293 of file Target.h.

References has_feature(), and LargeBuffers.

Referenced by maximum_buffer_size().

◆ maximum_buffer_size()

int64_t Halide::Target::maximum_buffer_size ( ) const
inline

Return the maximum buffer size in bytes supported on this Target.

This is 2^31 - 1 except on 64-bit targets when the LargeBuffers feature is enabled, which expands the maximum to 2^63 - 1.

Definition at line 300 of file Target.h.

References EXPORT, Halide::get_host_target(), Halide::get_jit_target_from_environment(), Halide::get_target_from_environment(), has_large_buffers(), supported(), Halide::target_feature_for_device_api(), and Halide::Internal::target_test().

◆ supported()

EXPORT bool Halide::Target::supported ( ) const

Was libHalide compiled with support for this target?

Referenced by maximum_buffer_size().

Member Data Documentation

◆ os

◆ arch

◆ bits

int Halide::Target::bits

The bit-width of the target machine.

Must be 0 for unknown, or 32 or 64.

Examples:
tutorial/lesson_11_cross_compilation.cpp.

Definition at line 33 of file Target.h.

Referenced by Halide::ExternalCode::is_for_cpu_target(), and operator==().


The documentation for this struct was generated from the following file: