Comments (1)
I tried to use pass float* and size_t* to wasm module. After using wasm_runtime_module_malloc(). I found that the absolute address is different. Here is my cpp code(I only copyed the part which has problem)
float* test_input; test_input=new float[5]{1.0,2.0,3.0,4.0,5.0}; std::cout<<test_input<<std::endl; uint32_t buffer_for_wasm_test_input=wasm_runtime_module_malloc(wasm_module_inst,sizeof(float)*5, (void**)&test_input); std::cout<<test_input<<std::endl; void* input=wasm_runtime_addr_app_to_native(wasm_module_inst, buffer_for_wasm_test_input); std::cout<<input<<std::endl; size_t* shape_input=new size_t[3]{1,1,5}; std::cout<<shape_input<<std::endl; uint32_t buffer_for_wasm_shape_input=wasm_runtime_module_malloc(wasm_module_inst,sizeof(size_t)*3,(void**)&shape_input); std::cout<<shape_input<<std::endl; void* test=wasm_runtime_addr_app_to_native(wasm_module_inst, buffer_for_wasm_shape_input); std::cout<<test<<std::endl;And the result is that
0x5605cbb7e420 0x7f4e9fa10610 0x7f4e9fa10610 0x5605cbb7e440 0x7f4e9fa10630 0x7f4e9fa10630
I am wondering why after using the wasm_runtime_module_malloc(), the pointer address is different. And if I want them to be same ,how to do that? Thank you!
Hi, the wasm_runtime_module_malloc
returns both the offset in the linear memory (buffer_for_wasm_test_input) and the absolute address of that offset in native (test_input = linear_base_addr + buffer_for_wasm_test_input), and you can convert them to each other by calling wasm_runtime_addr_app_to_native/wasm_runtime_addr_native_to_app.
I suppose you want to module_malloc the memory, and put the data into it, maybe you can:
float test_input_buf[5] = {1.0,2.0,3.0,4.0,5.0};
float* test_input = NULL;
uint32_t buffer_for_wasm_test_input=wasm_runtime_module_malloc(wasm_module_inst,sizeof(float)*5, (void**)&test_input);
if (buffer_for_wasm_test_input == 0)
return error;
memcpy(test_input, test_input_buf, sizeof(float) * 5);
...
from wasm-micro-runtime.
Related Issues (20)
- An invalid section specifier `.aot_stack_sizes` HOT 1
- AOT module load failed: resolve symbol __atomic_compare_exchange_4 failed HOT 7
- The qWasmStackValue command is missing during runtime debugging
- AOT_SECTION_TYPE_SIGNATURE HOT 2
- WASI sockets: POSIX platform `os_socket_recvfrom` unintended behavior HOT 7
- sysbench mutex workload is taking more execution time with iwasm than native x86_64 execution HOT 2
- sysbench memory and threads workload is giving less benchmarking results with iwasm than native aarch64 gcc execution HOT 11
- Updating Exception Handling in WAMR HOT 20
- [RFC] Option to reduce code size of the generated AOT file when stack trace is enabled HOT 7
- sysbench wasm module of CPU workload is giving unexpected results than native gcc compiled sysbench cpu workload.
- MIPS32 support / alignment issues HOT 11
- [RFC] Table64 extension for Memory64 proposal
- CI: "spec test on nuttx" riscv job is failing frequently HOT 12
- Access to call stack when calling native functions HOT 5
- wamr windows build error with clang HOT 1
- [RFC] Add SIMD128 support in the interpreters HOT 3
- wamr windows build error with UVWASI HOT 5
- [RFC] Support instantiation linking
- clang asan Segmentation fault. HOT 2
- clang & windows build should use longjmp HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasm-micro-runtime.