Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!

Silvi Hasana

Greenhorn
+ Follow
since Feb 21, 2019
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Silvi Hasana

John Matthews wrote:

Silvi Hasana wrote:but.. why...  


It might not answer your question, but to clarify, the 'single precision flag' doesn't mean the compiler only generates single precision code - it just means that the numeric literals are only held as single precision instead of the default of double precision. But this has the effect of an 'overall single precision flag' in this code because all the other values in the expressions are also single precision (float). Hence the compiler generates single precision code.

As soon as a double appears in an expression, eg. one of the numeric literals (without the single precision flag), the expression is calculated using double precision.

Using const float variables for the numeric literals is just another way of ensuring that no doubles appear in the expressions, so single precision is used.

Regarding -Ofast and -O3, it just might be that for this particular (relatively simple) code there is no difference.



Thanks a lot for detailed explanation! I completely understand now. Also, yes I tried -O0, only managed to get 14 fps.
2 months ago

Silvi Hasana wrote:

John Matthews wrote:

Silvi Hasana wrote:As for single point precision, yes I'm compiling with gcc. I tried it and I could get 29 fps but I'm working on a very small coordinate space and single precision isn't sufficient so I guess the flag isn't the best approach for me.


If you want/need double precision then all your float variables should be double.

Are you sure you need double? What is the effect - looks like you doing some sort of image processing, so is the difference visible? I'm curious



I have other functions too which really can't have single precision. But you're also correct, in the end the picture looks the same though. Now I'm having dilemma



ok, anyway I use the single precision option, lol. I tried the single precision flag before I read your other comment and then changed literal values to constant, and so far :
  • With single precision flag = 29 fps
  • With single precision flag + change literal value to constant variable + change -O to -Ofast = 29 fps


  • but.. why...  
    2 months ago

    John Matthews wrote:

    Silvi Hasana wrote:As for single point precision, yes I'm compiling with gcc. I tried it and I could get 29 fps but I'm working on a very small coordinate space and single precision isn't sufficient so I guess the flag isn't the best approach for me.


    If you want/need double precision then all your float variables should be double.

    Are you sure you need double? What is the effect - looks like you doing some sort of image processing, so is the difference visible? I'm curious



    I have other functions too which really can't have single precision. But you're also correct, in the end the picture looks the same though. Now I'm having dilemma
    2 months ago

    Silvi Hasana wrote:

    John Matthews wrote:

    John Matthews wrote:If you're not using gcc, look for an equivalent option for your compiler.


    ...or instead of using numeric literals, use const variables eg.



    Done ! It's 23 fps now ! It's small steps but it is improving and I learn a lot too. You're such a life saver.



    I changed all literal (in another function too) with constant, I also changed the compiler flag from -O to -Ofast (Source here), now I get 28 fps. For now I don't know how "not accurate" is -Ofast, I'm working on it.
    2 months ago

    John Matthews wrote:

    John Matthews wrote:If you're not using gcc, look for an equivalent option for your compiler.


    ...or instead of using numeric literals, use const variables eg.



    Done ! It's 23 fps now ! It's small steps but it is improving and I learn a lot too. You're such a life saver.
    2 months ago

    John Matthews wrote:Using -O3 certainly makes a big difference on my machine, where I'm using gcc. But I expected that; something else that also made a significant difference (>30%) was the option -fsingle-precision-constant "Treat floating point constant as single precision constant instead of implicitly converting it to double precision constant". If you're not using gcc, look for an equivalent option for your compiler.



    Thanks, I tried with O3 optimization and there's no difference. As for single point precision, yes I'm compiling with gcc. I tried it and I could get 29 fps but I'm working on a very small coordinate space and single precision isn't sufficient so I guess the flag isn't the best approach for me.
    2 months ago

    John Matthews wrote:One thing that made a small improvement on my machine was to remove some redundant code, ie.
    can (as I'm sure you're aware) be simplified to:



    Oh wow, thanks! I feel so stupid, but it's indeed improved. It's 22 fps now from 20 fps.
    2 months ago

    John Matthews wrote:Looking at a bit of the code, specifically lines 40/41...

    That doesn't look right



    Indeed ! my bad, it's supposed to be I can't edit my post, that's why.
    2 months ago

    John Matthews wrote:Hi Silvi

    Without examining the code...

    Probably a silly question, but have you enabled compiler optimisations, and tried playing with the various options to see which give the best results?

    Are you aware of AVX - Advanced Vector Extensions? Basically it allows the code to do multiple calculations in parallel. Assuming your CPU supports this, ensure your compiler set to generate the best code for your CPU. And take a look at stuff like this:
    https://software.intel.com/en-us/articles/using-avx-without-writing-avx-code

    Cheers
    John




    Hi, thanks. Actually, now I'm working with Intel i7 + Linux terminal + NVIDIA 1080Ti GPU which should be pretty fast and I'm not familiar with compiler optimization, I'll take a look at it. Also, if possible I want to improve the code so I'm not dependent on machine
    2 months ago
    Hi, I'm trying to do per-pixel image calculation. My program works, but not on my desire speed (fps).
    I have an image as input and after several computation, I want to apply pixel transformation (below). No matter if I put it in a function directly in the function in the main file or if I put it in a struct and then call it, my computation process is very slow.
    Without this calculation, I could get 40 fps and when I tried to put it directly into the function inside my main program that calculated the pixels (below) my fps was cut in a half (only 20fps).


    And when I tried to put it on a struct (like below) and then call it, my fps dropped into 18-19 fps


    I'm aware that the computation process also depends on the size of my image, but even with the same image I can get 40 fps when I disabled this calculation. Is there anyway I can improve this calculation ?
    2 months ago

    Tim Holloway wrote:And now that you've got you logic cleaned up, some suggestions about general style!



    Notice the extra braces I added? I learned to do that after too many time doing something like this:


    Which actually doesn't compile, but if the "else" wasn't there, it would compile just fine, not execute correctly, and waste me a day looking for the problem (the most obvious ones are always the hardest to catch). So the extra typing is well worth the effort.

    Beyond that, "x" and "y" don't mean anything to me as part of a "coffee" class. Are there more meaningful names you could use?



    Hi thanks !! I was aware of this one since I came across many times as well. Also, it's actually exactly what I did after received answer from John Matthews. I needed to add some extra lines, so I added the braces.  
    For the X and Y, they are amount of different ingredients needs to be added. I'm not the best at naming variable, it's not very descriptive and makes me run into trouble too sometimes (try to recall which one is which, for example). I usually in a rush and just write the first thing pops up in my head, I'll work on this naming variable better, thanks again !!
    3 months ago

    John Matthews wrote:However rather than have the ret field in Coffee, a better solution would be to remove it and use something like:



    This is indeed the most efficient way. I wasn't aware of this one too, thank you I learn a lot.
    4 months ago

    Anthony Aj Williams wrote:You need



    on the failure path and



    on the success path.

    You can't implicitly convert from an integer or boolean to a struct in C.



    I see. Thank you, it works.
    4 months ago

    Peter Sommerhoff wrote:Hi Rania,

    Luckily, programming languages *generally* keep improving with time because we learn more about good language design (although there are enough bad languages being created as well).

    I do hope and think that Kotlin will be a game changer in terms of gaining a lot more traction than it already has and being adopted more heavily on all platforms.

    But (hopefully) it'll be challenged a few decades later by the next even better programming language. Who knows what software development and programming languages will look like then...

    - Peter



    True. We, programmers and programming language are both keep improving, and at the same time some of the programming language need to retire as well. (I remember Pascal during middle school, it did retire for good.). As a student, I do believe small changes can bring big impact. For example one professor is using a specific programming language, then the whole class : "OMG LET'S USE THAT TOO!!". If Kotlin is really our next game changer, I hope academia will move fast to take and adapt it as well. Best wishes for all of us and Kotlin !!
    4 months ago

    Anthony Aj Williams wrote:If the return type of your function is "struct Coffee", then all return statements must return a value of type struct Coffee. The "failure" return path must therefore specify its failure in the return type itself, e.g. with special values, or via another means such as errno or by adding an extra function parameter which is a pointer to a success/failure value.



    Hi, I still don't quite get it, also I forgot to include struct Coffee, here it is :
    Earier I also I tried with adding to my struct  :
    Then in my function I added :
    But I encountered the same error.
    4 months ago