MCPcopy Create free account
hub / github.com/apache/arrow / parallel_memcopy

Function parallel_memcopy

cpp/src/arrow/util/memory.cc:40–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38} // namespace
39
40void parallel_memcopy(uint8_t* dst, const uint8_t* src, int64_t nbytes,
41 uintptr_t block_size, int num_threads) {
42 // XXX This function is really using `num_threads + 1` threads.
43 auto pool = GetCpuThreadPool();
44
45 uint8_t* left = pointer_logical_and(src + block_size - 1, ~(block_size - 1));
46 uint8_t* right = pointer_logical_and(src + nbytes, ~(block_size - 1));
47 int64_t num_blocks = (right - left) / block_size;
48
49 // Update right address
50 right = right - (num_blocks % num_threads) * block_size;
51
52 // Now we divide these blocks between available threads. The remainder is
53 // handled separately.
54 size_t chunk_size = (right - left) / num_threads;
55 int64_t prefix = left - src;
56 int64_t suffix = src + nbytes - right;
57 // Now the data layout is | prefix | k * num_threads * block_size | suffix |.
58 // We have chunk_size = k * block_size, therefore the data layout is
59 // | prefix | num_threads * chunk_size | suffix |.
60 // Each thread gets a "chunk" of k blocks.
61
62 // Start all parallel memcpy tasks and handle leftovers while threads run.
63 std::vector<Future<void*>> futures;
64
65 for (int i = 0; i < num_threads; i++) {
66 futures.push_back(*pool->Submit(wrap_memcpy, dst + prefix + i * chunk_size,
67 left + i * chunk_size, chunk_size));
68 }
69 memcpy(dst, src, prefix);
70 memcpy(dst + prefix + num_threads * chunk_size, right, suffix);
71
72 for (auto& fut : futures) {
73 ARROW_CHECK_OK(fut.status());
74 }
75}
76
77} // namespace internal
78} // namespace arrow

Callers 1

WriteMethod · 0.85

Calls 4

GetCpuThreadPoolFunction · 0.85
pointer_logical_andFunction · 0.85
push_backMethod · 0.80
statusMethod · 0.45

Tested by

no test coverage detected