MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / passesJitHeuristics

Function passesJitHeuristics

src/backend/opencl/Array.cpp:327–423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325/// limitation on the platform. For NVIDIA this is 4096 bytes. The
326template<typename T>
327kJITHeuristics passesJitHeuristics(span<Node *> root_nodes) {
328 if (!evalFlag()) { return kJITHeuristics::Pass; }
329 static auto getLogger = [&] { return common::loggerFactory("jit"); };
330 for (const Node *n : root_nodes) {
331 if (n->getHeight() > static_cast<int>(getMaxJitSize())) {
332 AF_TRACE(
333 "JIT tree evaluated because of tree height exceeds limit: {} > "
334 "{}",
335 n->getHeight(), getMaxJitSize());
336 return kJITHeuristics::TreeHeight;
337 }
338 }
339
340 bool isBufferLimit = getMemoryPressure() >= getMemoryPressureThreshold();
341 auto platform = getActivePlatformVendor();
342
343 // The Apple platform can have the nvidia card or the AMD card
344 bool isIntel = platform == AFCL_PLATFORM_INTEL;
345
346 /// Intels param_size limit is much smaller than the other platforms
347 /// so we need to start checking earlier with smaller trees
348 int heightCheckLimit =
349 isIntel && getDeviceType() == CL_DEVICE_TYPE_GPU ? 3 : 6;
350
351 // A lightweight check based on the height of the node. This is
352 // an inexpensive operation and does not traverse the JIT tree.
353 bool atHeightLimit =
354 std::any_of(std::begin(root_nodes), std::end(root_nodes),
355 [heightCheckLimit](Node *n) {
356 return (n->getHeight() + 1 >= heightCheckLimit);
357 });
358
359 if (atHeightLimit || isBufferLimit) {
360 // This is the base parameter size if the kernel had no
361 // arguments
362 size_t base_param_size =
363 (sizeof(T *) + sizeof(KParam)) * root_nodes.size() +
364 (3 * sizeof(uint));
365
366 const cl::Device &device = getDevice();
367 // typical values:
368 // NVIDIA = 4096
369 // AMD = 3520 (AMD A10 iGPU = 1024)
370 // Intel iGPU = 1024
371 //
372 // Setting the maximum to 5120 bytes to keep the compile times
373 // resonable. This still results in large kernels but its not excessive.
374 size_t max_param_size =
375 min(static_cast<cl::size_type>(5120),
376 device.getInfo<CL_DEVICE_MAX_PARAMETER_SIZE>());
377 max_param_size -= base_param_size;
378
379 struct tree_info {
380 size_t total_buffer_size;
381 size_t num_buffers;
382 size_t param_scalar_size;
383 };
384

Callers

nothing calls this directly

Calls 14

loggerFactoryFunction · 0.85
getActivePlatformVendorFunction · 0.85
beginFunction · 0.85
endFunction · 0.85
getDeviceFunction · 0.85
getHeightMethod · 0.80
isBufferMethod · 0.80
getMemoryPressureFunction · 0.70
getDeviceTypeFunction · 0.70
minFunction · 0.70

Tested by

no test coverage detected