VLOAD_HALF(3clc)
π VLOAD_HALF π β from the OpenCL Manual, section 3clc
okay bestie, sit down, hydrate, because today we're talking about vload_half, and it's genuinely one of the cutest lil loaders in the whole OpenCL lineup πΈ
β¨ NAME β¨
vload_half β read a half float from a pointer to memory. that's it, that's the whole job, and she does it flawlessly π
float vload_half(size_t offset, const __global half *p);
float vload_half(size_t offset, const __local half *p);
float vload_half(size_t offset, const __constant half *p);
float vload_half(size_t offset, const __private half *p);
four overloads, one queen π pick whichever memory space your pointer lives in, she's got you covered in every single one.
π¦ DESCRIPTION π¦
so what's actually happening here? she reads sizeof(half) bytes of data from the address (p + offset), and that data she just read? she interprets it as a half value. simple. elegant. no notes.
then β and this is the glow-up moment β¨ β that half value gets converted to a float value, and the float value is what gets returned to you.
β οΈ but listen, this part is NOT optional: the read address computed as (p + offset) must be 16-bit aligned. if it's not, that's an alignment problem and you do not want that energy.
and one more thing, bestie, because this trips people up literally every time π β an application that wants to use half and halfn types will need to include the #pragma OPENCL EXTENSION cl_khr_fp16(3clc) : enable directive. no pragma, no half types. periodt.
π NOTES π
Vector Data Load and Store Functions allow you to read and write vector types from a pointer to memory. that's the whole family, and vload_half is one of the iconic members π
the generic type gentype is used to indicate the built-in data types char, uchar, short, ushort, int, uint, long, ulong, float, or double. that's the full roster, no substitutions.
the generic type name gentypen represents n-element vectors of gentype elements. and the suffix n is also used in the function names (i.e. vloadn, vstoren, etc.), where n = 2, 3, 4, 8, or 16. so like. those are your options. there is no n = 5. do not try it π
π REAL TALK WARNING: the results of vector data load and store functions are undefined if the address being read from or written to is not correctly aligned. undefined. not "a little weird", not "maybe wrong", undefined. respect the alignment, protect your peace.
the pointer argument p can be a pointer to global(3clc), local(3clc), or private(3clc) memory for store functions.
the pointer argument p can be a pointer to __global, __local, constant(3clc) or __private memory for load functions. π that's us, that's the load girlies
π SPECIFICATION π
OpenCL Specification[1]
π«Ά SEE ALSO π«Ά
π AUTHORS π
The Khronos Group
π COPYRIGHT π
Copyright Β© 2007-2011 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.
π NOTES π
- OpenCL Specification β page 267, section 6.12.7 - Vector Data Load and Store Functions
and that's the whole page, bestie!! π§β¨ this one's from The Khronos Group, dated 01/14/2021, and you can find her filed under VLOAD_HALF(3clc) in the OpenCL Manual. go forth and load those halves, aligned and unbothered ππΈπ
π¦ where this page comes from
- ubuntu jammy: opencl-1.2-man-doc 1.0~svn33624-5 Β· other
- ubuntu noble: opencl-1.2-man-doc 1.0~svn33624-5 Β· other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms