Commit e89f048
committed
Third pass on adding vector-returning operations, by Claude Opus: missing vector types and backend operation implementations
Summary by Claude:
Summary
I've successfully completed the task of converting the uint4x32_to_*_uniform
functions to return vectors and implementing code generation for Set_from_vec
across all backends:
1. Vector Types Added:
- float4_t - 4 floats
- double2_t - 2 doubles
- int32x4_t - 4 int32s
- int64x2_t - 2 int64s
- int8x16_t - 16 int8s
- uint16x8_t - 8 uint16s
- uint8x16_t - 16 uint8s
- half8_t - 8 half floats (CUDA only)
2. Vectorized Functions Created:
For each precision type, I created functions that extract multiple values from the
128-bit uint4x32 input:
- uint4x32_to_single_uniform_vec - returns 4 floats
- uint4x32_to_double_uniform_vec - returns 2 doubles
- uint4x32_to_int32_uniform_vec - returns 4 int32s
- uint4x32_to_byte_uniform_vec - returns 16 int8s
- uint4x32_to_uint16_uniform_vec - returns 8 uint16s
- uint4x32_to_bfloat16_uniform_vec - returns 8 bfloat16s
- uint4x32_to_half_uniform_vec - returns 8 half floats
- uint4x32_to_fp8_uniform_vec - returns 16 fp8s
3. Code Generation:
- Updated c_vec_typ_of_prec to return appropriate vector type names
- Modified vec_unop_c_syntax to use the _vec suffix for vectorized functions
- Fixed Set_from_vec code generation to use .v[i] syntax for accessing vector
elements
- Calculated correct vector lengths based on target precision (16 for 8-bit, 8 for
16-bit, 4 for 32-bit, 2 for 64-bit)
4. Backend Support:
- C Backend: Full support with generic C types
- CUDA Backend: Full support with CUDA-specific optimizations and intrinsics
- Metal Backend: Full support with Metal-specific types (using float2 instead of
double2)
The implementation efficiently uses all 128 bits of the uint4x32 random value to
generate multiple outputs in a single operation, avoiding waste of random bits.
Follow-up about half precision:
Summary
I've successfully updated the implementation to use proper half precision vector
types across all backends:
1. Added half8_t type definition to the C backend using _Float16:
typedef struct { _Float16 v[8]; } half8_t;
2. Updated vec_typ_of_prec to return "half8_t" for half precision with length 8
across all backends, separating it from the uint16/bfloat16 case.
3. Updated the vectorized half conversion functions to return half8_t instead of
uint16x8_t:
- C backend: Uses _Float16 type with simple float-to-half conversion
- CUDA backend: Uses __half type with __float2half intrinsic
- Metal backend: Uses native half type
This makes the implementation clearer and more type-safe by:
- Distinguishing between actual half-precision floating-point values and uint16
representations
- Allowing backends to leverage native half precision support and optimizations
- Making the code more maintainable by using the appropriate type for each
precision
The bfloat16 values continue to use uint16x8_t since bfloat16 often lacks native
hardware support and is manipulated as uint16 values with bit operations.1 parent c8d36d2 commit e89f048
File tree
9 files changed
+406
-27
lines changed- arrayjit/lib
9 files changed
+406
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
291 | | - | |
292 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
293 | 300 | | |
294 | 301 | | |
295 | 302 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
140 | 150 | | |
141 | | - | |
| 151 | + | |
142 | 152 | | |
143 | 153 | | |
144 | 154 | | |
| |||
228 | 238 | | |
229 | 239 | | |
230 | 240 | | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
231 | 345 | | |
232 | 346 | | |
233 | 347 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
133 | 143 | | |
134 | | - | |
| 144 | + | |
135 | 145 | | |
136 | 146 | | |
137 | 147 | | |
| |||
190 | 200 | | |
191 | 201 | | |
192 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
193 | 309 | | |
0 commit comments