Skip to content

Commit b1d0b1e

Browse files
authored
Expanding external library docs
1 parent 7a4794b commit b1d0b1e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs_input/external.rst

+17
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ take ownership, and defaults to *false*. By setting `owning` to *true*, MatX wil
4444
By default it uses its own allocator, but users can pass in their own PMR-compatible allocator if they wish. For more information
4545
see :ref:`creating`.
4646

47+
MatX does not know the "space" or "kind" of the memory when a pointer is passed in. This is by design since looking up what kind
48+
of pointer is passed (device, host, managed, etc) is expensive and error-prone. In addition, what can be done with a pointer of a
49+
certain type is dependent on the system. For example, a Grace-Hopper system can share pointers allocated with `malloc` between the
50+
the GPU and CPU, but x86 cannot. It is up to the user to make sure that all memory types used in an expression are compatible.
51+
52+
.. code-block:: cpp
53+
54+
auto host_mem = reinterpret_cast<float*>(malloc(10 * sizeof(float)));
55+
auto host_tensor = make_tensor<float>(host_mem, {10});
56+
auto device_tensor = make_tensor<float>({10}, MATX_DEVICE_MEMORY);
57+
(device_tensor = host_tensor).run();
58+
59+
The code above attempts to copy memory from a malloc'd pointer on the host to device memory. This may or may not work depending
60+
on the system. If unsure, it's usually safe to make a tensor with managed memory, copy data into it, then use it on both host or
61+
device.
62+
63+
4764
Passing MatX Operators to External Code/Libraries
4865
-------------------------------------------------
4966

0 commit comments

Comments
 (0)