Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python API about the Shared Memory Transport #42

Closed
cdp-study opened this issue Aug 29, 2022 · 7 comments
Closed

Python API about the Shared Memory Transport #42

cdp-study opened this issue Aug 29, 2022 · 7 comments

Comments

@cdp-study
Copy link

I want to use Fast-DDS-Python transfers the 900K data, but I find it too slow to transfer data. By viewing the answers to the corresponding questions in Fast-DDS, I need to use the Shared Memory Transport. But I don't find it in the Python API. Can you tell me how to implement the corresponding functions with the Fast-DDS-Python?

@duchengyao
Copy link

Did you find a solution >_<

@jsan-rt
Copy link
Contributor

jsan-rt commented Oct 26, 2022

Hi @cdp-study , @duchengyao ,

At this moment it's not possible to define the user transports using the Python API. However, by default Fast DDS uses both an UDPv4 transport and a Shared Memory transport, the latter being preferred for data transfer if communication is possible.

Could you provide us with some more information (like the IDL used to generate the type) or a minimal reproducer?

@duchengyao
Copy link

duchengyao commented Oct 27, 2022

@jsantiago-eProsima Thanks for reply.

For example, I'd like to receive data from example/HelloWorldExampleSharedMem .

  1. I modified HelloWorld.idl #L5 to char data[1048576]; because of this issue
  2. Generated and build using fastddsgen -python HelloWorld.idl mkdir build; cmake ..; make
  3. Copied HelloWorldExample.py to build folder. And modified the topic name to "HelloWorldSharedMemTopic", "HelloWorld".

Then, I run publisher of C++ and subscriber of python. The subscriber cannot receive any data.

But after delete this line pqos.transport().use_builtin_transports = false; #L57 ,the subscriber could receive data.

So, maybe the python binding cannot receive data of shared memory.
Is there the way to receive data of HelloWorldExampleSharedMem without modify the code of C++?

Thanks!

@jsan-rt
Copy link
Contributor

jsan-rt commented Oct 27, 2022

You could use an XML profile like the one shown here to setup the available descriptors for your participant. This XML can be loaded either from a file or from a string.

If the profile is not set as default, you can specify it manually on participant creation with the create_participant_with_profile call.

@duchengyao
Copy link

duchengyao commented Nov 15, 2022

@jsantiago-eProsima I have successfully used shared memory via XML, thanks!

BTW,
Converting SWIG type to numpy or list will consume a lot of time. I can't find the solution about that, could you please provide an example, thank you ^_^

python:

data.raw_data()
>>    <...;proxy of <Swig Object of type 'std::array< float,512*16000 > *' at 0x7fb...> >

a = list(data.raw_data())        # cost long time
b = np.array(data.raw_data())    # cost long time

And I try using ctypes to accelerate speed of converting data.

a = np.frombuffer((ctypes.c_float*512*16000).from_address(0x7fb..),np.float32)

But I cannot get the address using variable. Can I get the address like data.raw_data().get_address() ?

@JesusPoderoso
Copy link
Contributor

JesusPoderoso commented Nov 6, 2023

Hi @duchengyao, sorry for the late response. The data conversion has been improved in this PR, which introduces a get_buffer() method that returns the data buffer. The time cost reduction is significant, but its usage is quite similar to the solution you reached:

a = np.frombuffer((ctypes.c_float*512*16000).from_address(int(data.get_buffer())),np.float32)

But I cannot get the address using variable. Can I get the address like data.raw_data().get_address() ?

Regarding this, the get_buffer() method can be used on the defined types: data.address().get_buffer().

@JesusPoderoso
Copy link
Contributor

I am moving this issue to the support discussion forum as per our CONTRIBUTING guidelines.

@eProsima eProsima locked and limited conversation to collaborators Nov 27, 2023
@JesusPoderoso JesusPoderoso converted this issue into discussion #72 Nov 27, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

4 participants