Hangs in vsprintf() - printf

I'm programming on stm32f407 and using vsprintf to access all the the arguments assigned to argv such as:
va_list argv;
va_start(argv, __format);
vsprintf(buffer, __format, argv);
va_end(argv);
But the program hangs in vsprintf.
I modified stm32_flash.ld :
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
PROVIDE ( __end__ = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >RAM
And Cpu flags in Makefile:
CFLAGS += --specs=rdimon.specs -Wl,--start-group -lgcc -lc -lm -lrdimon -Wl,--end-group
Does anyone know how to solve this issue? Please help me. Thanks so much.

Related

How to mix compile HIP and Fortran using CMake

I don't know how to mix HIP compilation and Fortran using CMake. The follow is a demo.
I have 3 files:
fcode.f90
SUBROUTINE fcode()
implicit double precision (a-h, o-z)
parameter (M=64)
dimension x(M),y(M),z(M)
do k=1, M
x(k) = 1.0
y(k) = 2.0
z(k) = 0.0
end do
call hipcode(x,y,z,M)
do k = 1, M
if ( z(k) .ne. 3.0 ) then
write(6,*) 'u fail !'
return
endif
end do
write(6,*)' PASSED !'
return
end
hipcode.cpp
#include <hip/hip_runtime.h>
#define HIP_ASSERT(status) assert(status == hipSuccess)
__global__ void add(double *x, double *y, double *z, const unsigned int M) {
z[threadIdx.x] = x[threadIdx.x] + y[threadIdx.x];
}
extern "C" void hipcode_(double *h_x, double *h_y, double *h_z, int &M) {
HIP_ASSERT(hipSetDevice(0));
double *d_x, *d_y, *d_z;
HIP_ASSERT(hipMalloc((void **)&d_x, M * sizeof(double)));
HIP_ASSERT(hipMalloc((void **)&d_y, M * sizeof(double)));
HIP_ASSERT(hipMalloc((void **)&d_z, M * sizeof(double)));
HIP_ASSERT(hipMemcpy(d_x, h_x, M * sizeof(double), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(d_y, h_y, M * sizeof(double), hipMemcpyHostToDevice));
HIP_ASSERT(hipMemcpy(d_z, h_z, M * sizeof(double), hipMemcpyHostToDevice));
hipLaunchKernelGGL(add, 1, 64, 0, 0, d_x, d_y, d_z, M);
HIP_ASSERT(hipMemcpy(h_z, d_z, M * sizeof(double), hipMemcpyDeviceToHost));
hipFree(d_x);
hipFree(d_y);
hipFree(d_z);
}
main.f90
call fcode()
stop
end
and I write a Makefile to compile it, it works. But I don't know how to use cmake to do this.
OBJS=main.o fcode.o hipcode.o
FC=gfortran
HIPCC=hipcc
FCFLAGS=-c
HIPCCFLAGS=-c
LDFLAGS=-lgfortran
all :
$(HIPCC) $(HIPCCFLAGS) hipcode.cpp
$(FC) $(FCFLAGS) fcode.f90
$(FC) $(FCFLAGS) main.f90
$(HIPCC) $(OBJS) $(LDFLAGS) -o test
Here is my CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(test LANGUAGES Fortran CXX)
# source file: hipcode.cpp fcode.f90 main.f90
# target:
# hipcc -c hipcode.cpp
# gfortran -c fcode.f90
# gfortran -c main.f90
# hipcc hipcode.o fcode.o main.o -lgfortran -o test
set(sources_list hipcode.cpp)
set(raw_sources_list_f90 fcode.f90)
# find hip
find_package(HIP QUIET)
set(CMAKE_HIP_FLAGS "${CMAKE_CXX_FLAGS} -D__HIP_PLATFORM_HCC__ --offload-arch=gfx906")
set(HIP_CLANG_FLAGS "${HIP_CLANG_FLAG} --hip-link")
set_source_files_properties(${sources_list} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
set(MY_SOURCE_FILES ${sources_list})
set(MY_TARGET_NAME hipcode)
set(MY_HIPCC_OPTIONS "--hip-link")
set(HIP_TARGET_LINK_LIB "rocm/hip/lib/libamdhip64.so" )
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x hip -fgpu-rdc --hip-link -std=c++14 -g")
set(CMAKE_CXX_COMPILER "hipcc")
set(CMAKE_HIP_FLAFS "${CMAKE_HIP_FLAGS} --hip-link")
set(CMAKE_HIP_LINKER_WRAPPER_FLAG "--hip-link")
set(CMAKE_CXX_LINK_FLAGS " -fgpu-rdc --hip-link -std=c++14 ")
set(HIP_HIPCC_CMAKE_LINKER_HELPER "hipcc")
set(HIP_CLANG_PATH " ")
set(HIP_CLANG_PARALLEL_BUILD_LINK_OPTIONS " ")
add_library(${MY_TARGET_NAME} ${MY_SOURCE_FILES})
target_link_libraries(${MY_TARGET_NAME} ${HIP_TARGET_LINK_LIB} )
add_library(fcodef90 STATIC ${raw_sources_list_f90})
target_link_libraries(fcodef90 hipcode)
I use CXX=hipcc cmake .. && make -j to build the demo, and it passed.
But then I got an error: "undefined reference to `hipcode_'", so how to modify the CMakeLists.txt?
First of all thank you again, after use nm, I realized that maybe I need to add separate compilation options, then I found answer here, all right, thank you very much!
And the final compiled command is
gfortran -c main.f90
hipcc -fgpu-rdc --hip-link main.o libfcode.a libhipcode.a -lgfortran

Not getting appledoc to document NS_ENUM

could someone please explain what I am doing wrong when documenting my typedef NS_ENUM?
This is my syntax:
/** The different menu items
*/
typedef NS_ENUM(NSInteger, kMenuItem) {
/** The start page */
kMenuItemStartPage = 0,
/** The new round item */
kMenuItemNewRound,
/** The archive item */
kMenuItemArchive,
/** The participants item */
kMenuItemMyParticipants,
/** The locations item */
kMenuItemMyLocations,
/** The settings */
kMenuItemSettings,
/** The contact page */
kMenuItemContact,
/** The count */
kMenuItemTotal
};
/**
* This is the Menu View Controller.
*
* The menu view controller handles the menu the menu and its options. You can access the menu view controller using the `menuContainer` in the `ApplicationDelegate`
*
*/
#interface MenuTVC : UITableViewController
#end
My run script build phase:
APPLEDOC_PATH=`which appledoc`
if [ $APPLEDOC_PATH ]; then
echo "Generating docs!";
$APPLEDOC_PATH \
--project-name "${PRODUCT_NAME}" \
--project-company "Sogeti Sverige AB" \
--company-id "se.domain.project" \
--output "Docs" \
--no-install-docset \
--exit-threshold "2" \
--keep-undocumented-objects \
--keep-undocumented-members \
--keep-intermediate-files \
--ignore "Pods" \
--ignore ".m" \
--index-desc "${PROJECT_DIR}/Readme.md" \
${PROJECT_DIR}/Prevent
else
echo "AppleDoc not found or installed!"
fi;
The result:
And build result:
From the terminal:
$ which appledoc
/usr/bin/appledoc
$ appledoc --version
appledoc version: 2.2 (build 963)
I just can't seem to figure it out.
Thanks in advance!
I just figured out that the enums are documented in the index.html file, and not the class documentation itself.
It does work.
Appledoc doesn't currently support enums. It's quite a, shall we say, popular feature request:
https://github.com/tomaz/appledoc/issues/2

Rust optimizing out loops?

I was doing some very simple benchmarks to compare performance of C and Rust. I used a function adding integers 1 + 2 + ... + n (something that I could verify by a computation by hand), where n = 10^10.
The code in Rust looks like this:
fn main() {
let limit: u64 = 10000000000;
let mut buf: u64 = 0;
for u64::range(1, limit) |i| {
buf = buf + i;
}
io::println(buf.to_str());
}
The C code is as follows:
#include <stdio.h>
int main()
{
unsigned long long buf = 0;
for(unsigned long long i = 0; i < 10000000000; ++i) {
buf = buf + i;
}
printf("%llu\n", buf);
return 0;
}
I compiled and run them:
$ rustc sum.rs -o sum_rust
$ time ./sum_rust
13106511847580896768
real 6m43.122s
user 6m42.597s
sys 0m0.076s
$ gcc -Wall -std=c99 sum.c -o sum_c
$ time ./sum_c
13106511847580896768
real 1m3.296s
user 1m3.172s
sys 0m0.024s
Then I tried with optimizations flags on, again both C and Rust:
$ rustc sum.rs -o sum_rust -O
$ time ./sum_rust
13106511847580896768
real 0m0.018s
user 0m0.004s
sys 0m0.012s
$ gcc -Wall -std=c99 sum.c -o sum_c -O9
$ time ./sum_c
13106511847580896768
real 0m16.779s
user 0m16.725s
sys 0m0.008s
These results surprised me. I did expected the optimizations to have some effect, but the optimized Rust version is 100000 times faster :).
I tried changing n (the only limitation was u64, the run time was still virtually zero), and even tried a different problem (1^5 + 2^5 + 3^5 + ... + n^5), with similar results: executables compiled with rustc -O are several orders of magnitude faster than without the flag, and are also many times faster than the same algorithm compiled with gcc -O9.
So my question is: what's going on? :) I could understand a compiler optimizing 1 + 2 + .. + n = (n*n + n)/2, but I can't imagine that any compiler could derive a formula for 1^5 + 2^5 + 3^5 + .. + n^5. On the other hand, as far as I can see, the result must've been computed somehow (and it seems to be correct).
Oh, and:
$ gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
$ rustc --version
rustc 0.6 (dba9337 2013-05-10 05:52:48 -0700)
host: i686-unknown-linux-gnu
Yes, compilers do use the 1 + ... + n = n*(n+1)/2 optimisation to remove the loop, and there are similar tricks for any power of the summation variable. e.g. k1 are triangular numbers, k2 are pyramidal numbers, k3 are squared triangular numbers, etc. In general, there is even a formula to calculate ∑k kp for any p.
You can use a more complicated expression, so that the compiler doesn't have any tricks to remove the loop. e.g.
fn main() {
let limit: u64 = 1000000000;
let mut buf: u64 = 0;
for u64::range(1, limit) |i| {
buf += i + i ^ (i*i);
}
io::println(buf.to_str());
}
and
#include <stdio.h>
int main()
{
unsigned long long buf = 0;
for(unsigned long long i = 0; i < 1000000000; ++i) {
buf += i + i ^ (i * i);
}
printf("%llu\n", buf);
return 0;
}
which gives me
real 0m0.700s
user 0m0.692s
sys 0m0.004s
and
real 0m0.698s
user 0m0.692s
sys 0m0.000s
respectively (with -O for both compilers).

Undefined reference to `oslIsWlanPowerOn'

I am developing a PSP homebrew application and I using the makefile from the exampel but it won't link because the stupid (excuse my French) linker says that oslIsWlanPowrOn is undefined. I know I am linking the right library, plus I am following an example so it should compile. I know most stackoverflow users don't use the oslib or do much psp programming but any help would be appreciated. I have also tried reordering the order of the libs but still states the same linker errors. Anyhow here is the code below:
Makefile
TARGET = main
OBJS = main.o
CFLAGS = -O2 -g -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LIBS= -lpspwlan -losl -lpng -lz -lpspnet \
-lpsphprm -lpspsdk -lpspctrl -lpsprtc -lpsppower -lpspgu -lpspgum -lpspaudiolib -lpspaudio \
-lpspnet_adhocmatching -lpspnet_adhoc -lpspnet_adhocctl -lm -ljpeg
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = PSP Chat
#PSP_EBOOT_ICON = ICON0.PNG
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Error details:
1>------ Build started: Project: PSP Chat, Configuration: Debug Win32 ------
1> psp-gcc -I. -IC:/pspsdk/psp/sdk/include -O2 -g -G0 -Wall -D_PSP_FW_VERSION=150 -L. -LC:/pspsdk/psp/sdk/lib main.o -lpspwlan -losl -lpng -lz -lpspnet -lpsphprm -lpspsdk -lpspctrl -lpsprtc -lpsppower -lpspgu -lpspgum -lpspaudiolib -lpspaudio -lpspnet_adhocmatching -lpspnet_adhoc -lpspnet_adhocctl -lm -ljpeg -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o main.elf
1> main.o: In function `main':
1> c:\Users\Danny\documents\visual studio 2010\Projects\PSP Chat\PSP Chat/main.cpp (24) : undefined reference to `oslIsWlanPowerOn'
1> c:\Users\Danny\documents\visual studio 2010\Projects\PSP Chat\PSP Chat/main.cpp (52) : undefined reference to `oslIsWlanPowerOn'
1> C:\pspsdk\bin\make: *** [main.elf] Error 1
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
main.cpp
#include <pspkernel.h>
#include <oslib\oslib.h>
PSP_MODULE_INFO("PSP Chat", 0, 1, 0);
OSL_FONT* font;
int main()
{
char* screename = (char*)malloc(100);
int skip = 0;
printf("Initializing OSL...");
oslInit(0);
printf("Loading Font...");
oslIntraFontInit(INTRAFONT_CACHE_MED);
font = oslLoadFontFile("flash0:/font/ltn0.pgf");
printf("Configuring Font Style...");
oslIntraFontSetStyle(font, 1.0, RGBA(0, 0, 255, 255), RGBA(0, 0, 0, 0), INTRAFONT_ALIGN_LEFT);
printf("Setting Font...");
oslSetFont(font);
while(!osl_quit)
{
if (!skip)
{
oslStartDrawing();
if (oslIsWlanPowerOn())
{
oslDrawString(10, 10, "Please Enter Screename By Pressing X (Client)...");
oslDrawString(10, 25, "Please Press O To Act As Server...");
if (oslOskIsActive()){
oslDrawOsk();
if (oslGetOskStatus() == PSP_UTILITY_DIALOG_NONE)
{
if (oslOskGetResult() == OSL_OSK_CANCEL)
{
screename = (char*)"Client";
}
else
{
oslOskGetText(screename);
}
oslEndOsk();
}
}
else
{
oslDrawString(10, 10, "Please turn on the wlan switch!");
}
oslEndDrawing();
}
oslEndFrame();
skip = oslSyncFrame();
oslReadKeys();
if (osl_keys->released.cross && oslIsWlanPowerOn())
{
oslInitOsk((char*)"Please enter screename!", (char*)"Client", 99, 1, -1);
}
}
}
sceKernelExitGame();
return 0;
}
There was a problem with the installation of the sdk and so I reinstalled it. Voila--it worked.
Thanks for everyone who tried to diagnose the problem.

Building release version of a project with Android NDK r6

I am compiling helloworld example of Android NDK r6b using cygwin and Windows Vista. I have noticed that the following code takes between 14 and 20 mseconds on my Android phone (it has an 800mhz CPU Qualcomm MSM7227T chipset, with hardware floating point support):
float *v1, *v2, *v3, tot;
int num = 50000;
v1 = new float[num];
v2 = new float[num];
v3 = new float[num];
// Initialize vectors. RandomEqualREAL() returns a floating point number in a specified range.
for ( int i = 0; i < num; i++ )
{
v1[i] = RandomEqualREAL( -10.0f, 10.0f );
if (v1[i] == 0.0f) v1[i] = 1.0f;
v2[i] = RandomEqualREAL( -10.0f, 10.0f );
if (v2[i] == 0.0f) v2[i] = 1.0f;
}
clock_t start = clock() / (CLOCKS_PER_SEC / 1000);
tot = 0.0f;
for ( int k = 0; k < 1000; k++)
{
for ( int i = 0; i < num; i++ )
{
v3[i] = v1[i] / (v2[i]);
tot += v3[i];
}
}
clock_t end = clock() / (CLOCKS_PER_SEC / 1000);
printf("time %f\n", tot, (end-start)/1000.0f);
On my 2.4ghz notebook it takes .45 msec (timings taken when the system is full of other programs running, like Chrome, 2/3 ides, .pdf opens etc...). I wonder if the helloworld application is builded as a release version. I noticed that g++ get called with
-msoft-float.
Does this means that it is using floating point emulations?
What command line options i need to use in order to build an optimized version of the program? How to specify those options?
This is how g++ get called.:
/cygdrive/d/android/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebu
ilt/windows/bin/arm-linux-androideabi-g++ -MMD -MP -MF D:/android/workspace/hell
oworld/obj/local/armeabi/objs/ndkfoo/ndkfoo.o.d.org -fpic -ffunction-sections -f
unwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_
5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -f
no-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -f
inline-limit=64 -ID:/android/workspace/helloworld/jni/boost -ID:/android/workspa
ce/helloworld/jni/../../mylib/jni -ID:/android/android-ndk-r6b/sources/cxx-stl/g
nu-libstdc++/include -ID:/android/android-ndk-r6b/sources/cxx-stl/gnu-libstdc++/
libs/armeabi/include -ID:/android/workspace/helloworld/jni -DANDROID -Wa,--noex
ecstack -fexceptions -frtti -O2 -DNDEBUG -g -ID:/android/android-ndk-r6b/plat
forms/android-9/arch-arm/usr/include -c D:/android/workspace/helloworld/jni/ndk
foo.cpp -o D:/android/workspace/helloworld/obj/local/armeabi/objs/ndkfoo/ndkfoo.
o && ( if [ -f "D:/android/workspace/helloworld/obj/local/armeabi/objs/ndkfoo/nd
kfoo.o.d.org" ]; then awk -f /cygdrive/d/android/android-ndk-r6b/build/awk/conve
rt-deps-to-cygwin.awk D:/android/workspace/helloworld/obj/local/armeabi/objs/ndk
foo/ndkfoo.o.d.org > D:/android/workspace/helloworld/obj/local/armeabi/objs/ndkf
oo/ndkfoo.o.d && rm -f D:/android/workspace/helloworld/obj/local/armeabi/objs/nd
kfoo/ndkfoo.o.d.org; fi )
Prebuilt : libstdc++.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/libs/armeabi
/
cp -f /cygdrive/d/android/android-ndk-r6b/sources/cxx-stl/gnu-libstdc++/libs/arm
eabi/libstdc++.a /cygdrive/d/android/workspace/helloworld/obj/local/armeabi/libs
tdc++.a
SharedLibrary : libndkfoo.so
/cygdrive/d/android/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebu
ilt/windows/bin/arm-linux-androideabi-g++ -Wl,-soname,libndkfoo.so -shared --sys
root=D:/android/android-ndk-r6b/platforms/android-9/arch-arm D:/android/workspac
e/helloworld/obj/local/armeabi/objs/ndkfoo/ndkfoo.o D:/android/workspace/hellow
orld/obj/local/armeabi/libstdc++.a D:/android/android-ndk-r6b/toolchains/arm-lin
ux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3
/libgcc.a -Wl,--no-undefined -Wl,-z,noexecstack -lc -lm -lsupc++ -o D:/androi
d/workspace/helloworld/obj/local/armeabi/libndkfoo.so
Install : libndkfoo.so => libs/armeabi/libndkfoo.so
mkdir -p /cygdrive/d/android/workspace/helloworld/libs/armeabi
install -p /cygdrive/d/android/workspace/helloworld/obj/local/armeabi/libndkfoo.
so /cygdrive/d/android/workspace/helloworld/libs/armeabi/libndkfoo.so
/cygdrive/d/android/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebu
ilt/windows/bin/arm-linux-androideabi-strip --strip-unneeded D:/android/workspac
e/helloworld/libs/armeabi/libndkfoo.so
Edit.
I have run the commnad adb shell cat /proc/cpuinfo. This is the result:
Processor : ARMv6-compatible processor rev 5 (v6l)
BogoMIPS : 532.48
Features : swp half thumb fastmult vfp edsp java
CPU implementer : 0x41
CPU architecture: 6TEJ
CPU variant : 0x1
CPU part : 0xb36
CPU revision : 5
Hardware : GELATO Global board (LGE LGP690)
Revision : 0000
Serial : 0000000000000000
I don't understand what swp, half thumb fastmult vfp edsp and java means, but i don't like that 'vfp'!! Does it means virtual-floating points? That processor should have a floating point unit...
You are right, -msoft-float is a synonym for -mfloat-abi=soft (see list of gcc ARM options) and means floating point emulation.
For hardware floating point the following flags can be used:
LOCAL_CFLAGS += -march=armv6 -marm -mfloat-abi=softfp -mfpu=vfp
To see what floating point unit you really have on your device you can check the output of adb shell cat /proc/cpuinfo command. Some units are compatible with another: vfp < vfpv3-d16 < vfpv3 < neon - so if you have vfpv3, then vfp also works for you.
Also you might want to add the line
APP_OPTIM := release
into your Application.mk file. This setting overrides automatic 'debug' mode for native part of application if the manifest sets android:debuggable to 'true'
But even with all these settings NDK will put -march=armv5te -mtune=xscale -msoft-float into the beginning of compiler options. And this behavior can not be changed without modifications in NDK sources (these options are hardcoded in file $NDKROOT\toolchains\arm-linux-androideabi-4.4.3\setup.mk).