-
Notifications
You must be signed in to change notification settings - Fork 22
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
switch to decNumber? #12
Comments
One thing I don't like about decNumber is that it seems to use pass-by-reference for everything, which seems silly for passing and returning 32- and 64-bit values. It may not make much performance difference (since the operations themselves are so expensive), but will make the Julia glue code significantly uglier. |
Well, you've got the source, does the ICU license allow you to modify that? |
@stevengj I'm very willing to help out in getting decNumber to work in Julia, I was going to do it myself, but I don't yet have your mad skills in writing Julia code... I was very impressed by the way you generated all of the functions for the binding... cool! |
The ICU license certainly allows the code to be modified; I wouldn't consider using it otherwise. But we are talking about a lot of functions, so I'd be hesitant to go through and change it to pass-by-value unless the process could be automated. It's not too terrible to use pass-by-reference in Julia. For speed (to avoid heap-allocating |
(Yes, the code-generation features of Julia make it a lot easier to wrap these kinds of libraries, because there are zillions of functions with very similar call signatures.) |
I think we'll be needing this soon, so I'll definitely be testing this package ASAP... (it seems that love of Julia is spreading quickly at the startup I'm consulting for 😀 I think shortly some other people from the company will be contributing, some core work, improving some packages such as ODBC, and possibly adding some new packages) |
"back 20 years ago they (like me) had to deal with pure 32-bit platforms" I'm confused.. The decimal types didn't exist then(?) Are we talking about similar libraries? Yes, decimal is not new. The packed format is I thought. And, yes, the non-packed version is used, but I thought that came after the packed one. I've never quite understood how both the packed and non-packed are supposed to be supported. Implementations defined? Do you just stick with either one (non-packed)? Dealing with the out-side-world must, files using these bittypes or APIs, must factor in.. For now we need not worry about actual hardware (using packed) in PowerPC (right?) while Julia support for it is worked on or for SPARC. |
@PallHaraldsson Back then, with the 32-bit machines, the memory model was ILP32, i.e. int, long, and pointer types were all 32-bit, and often the C compilers did not yet support structure passing... so if you wanted to return 64-bit or 128-bit types, which this package does, you had to do so by passing a reference. That is what makes the Julia wrapper more difficult, as @stevengj commented on. Scott |
Yes, my feeling is that for the packed format we should only implement conversions, not arithmetic, so from Julia's perspective it is a storage-only format. |
@ScottPJones, I programmed a lot of 32-bit machines, but I'm having trouble recalling a compiler which did not support passing or returning My suspicion is that Anyway, whatever the reason, we need to deal with it to use |
@stevengj I started programming in the early 70's... (I was in 6th grade... taking courses at the state university), so I have a LOT of dark memories I'd like to suppress! [Think stacks of punched cards, written in Fortran 1966, and later in PL/1]. About C, it wasn't until sometime in mid '90s, that we were finally able to move to ANSI C completely, after waiting 5 years after the standard came out until the last platform that we actively developed for (as opposed to maintanence / bug fixing)... I used a lot of macro tricks to take advantage of ANSI C wherever I could, but that wasn't always easy. About the packed format, yes, that's exactly what I'd thought, when I was starting to look at writing a binding for it for Julia... I do also want the arbitrary precision support, not really for doing calculations, but just for parsing and storing numbers coming from JSON and later outputting them... |
@stevengj I'll try to take time off from annoying Stefan about numeric literal inconsistencies and string performance issues ;-) and download the Intel library, figure out out to use it, and add up 10000 numbers! |
Right now, I do not have time (or 0.4..) but I was going to test this with 2015-05-01 22:40 GMT+00:00 Scott P. Jones [email protected]:
Palli. |
@stevengj Here are some initial results... this is with the arbitrary precision decNumber type, not even using the shorter types... julia> @time run(dec)
(1.25 + 2.55) => 25500000001.25, 255
elapsed time: 255.405512641 seconds (9 MB allocated)
julia> @time run(dbl)
(1.250000 + 2.550000) => 25499995395.430843, 24
elapsed time: 23.543102345 seconds (1 kB allocated) So, it is only about 10x slower than C double... (and gets correct results!) Can you run that comparison for your Intel library? int main(int argc, char *argv[]) {
double numa, numb;
numa = 1.25;
numb = 2.55;
long ts = time(0);
for (long i=0; i<10000000000; i++) {
numa += numb;
}
long te = time(0);
printf("(%f + %f) => %f, %ld\n", 1.25, 2.55, numa, te - ts);
return 0;
} // main int main(int argc, char *argv[]) {
decNumber numa, numb; // working decNumbers
decContext set; // working context
char string[DECQUAD_String]; // number->string buffer
if (argc<3) { // not enough words
printf("Please supply two numbers for a + b).\n");
return 1;
}
decContextDefault(&set, DEC_INIT_DECQUAD); // initialize
decNumberFromString(&numa, argv[1], &set); // get a
decNumberFromString(&numb, argv[2], &set);
long ts = time(0);
for (long i=0; i<10000000000; i++) {
decNumberAdd(&numa, &numa, &numb, &set); // numa=numa + numb
}
long te = time(0);
decNumberToString(&numa, string); // ..
printf("(%s + %s) => %s, %ld\n", argv[1], argv[2], string, te - ts);
return 0;
} // main |
2015-05-03 20:48 GMT+00:00 Scott P. Jones [email protected]:
I actually though about doing some fast path - by wrapping a slow decimal |
@PallHaraldsson Did I say that I thought that? I've already said that I think the Intel library likely might be faster on Intel hardware (just an assumption that Intel would optimize it greatly), and so we might want to use both libraries on Intel hardware... also decNumber supports most platforms, the Intel library only Intel chips (x86-32, x86-64, ia64). |
"Did I say that I thought that?" No you didn't say the library was better, just implied with 10x. Since the Intel library was 100x slower I just wanted to make sure it wasn't discounted by not looking to carefully. https://software.intel.com/en-us/articles/optimization-notice#opt-en imply to me in-line assembly in library but.. http://www.netlib.org/misc/intel/README.txt "note that tests involving 80-bit binary floating-point values (these are since IA-64 doesn't have SSE etc. (right?) the library might be more portable than you think. If they just not emulate x86 there then either they also have IA-64 assembly or just portable C code. I wander if the notice is generic.. Also I thought all x86 had 80-bit (including IA-64, or kind of 82-bit..)?) [Intel had used dirty tricks against AMD (for benchmarking) in the past but it's easy enough to test if the library works (as well) there.] ARM (and PowerPC) support are coming to Julia, could also be tested, at least ARM even right now I think (or just try to cross-compile the library). [I'm not too worried about PowerPC, in that case when it comes, you might even want top use the built-in instructions and not having to worry about the same library.. except then you would be using packed..] https://software.intel.com/en-us/articles/intel-decimal-floating-point-math-library IBM's POWER6 (2007) and System z10 (2008) processors both implement IEEE 754-2008 fully in hardware and in every core. By the time they shipped there was much less uncertainty about the final standard. If you're a "CPU geek," there's a technical paper describing the z10 hardware implementation here: http://www.research.ibm.com/journal/abstracts/rd/531/schwarz.html The z10 DFP implementation is very similar to POWER6. There are 54 DFP instructions implemented in hardware, and they are common to the POWER6 and z10 CPUs (and z9, for that matter). The z10 decimal floating point unit adds support for 13 decimal fixed-point instructions, but these are simply preexisting instructions traditionally important to the z CPU family that were relocated and reimplemented for z10, to improve their performance." I can't locate my Julia code for bit-stealing fast-path.. It was only meant to be a proof-of-concept and not finished as I had too have a real library bit-type for the fallback. The decimal type would also not be fully conformant (only have half the numbers or some hairy code to fix that..). I was just thinking about this as a hobby Julia and decimal learning experiment. I do not actually have a use fur this code and can't really see that decimal binary floating point in software or hardware is needed for currency. I was just thinking of doing decimal fixed-point, scaled by 100x. Anyway if I'm mistaken and the range and more than two decimal places and/or NaN and all is needed then I thought the fallback could take care of that. Wouldn't the 9 MB allocation be because of pass_by_reference? I' do not know about the other library but saw in this one (and since possible and if not there could be added?): http://www.netlib.org/misc/intel/README.txt (a) Function arguments and return values can be passed by reference if |
@PallHaraldsson I'm sorry you thought I was implying that... I'd like to do the same with decimal floating point... the things I most want to test are: Yes, I am a CPU geek also... I ported to the RS/6000 at IBM's request, before it was released publicly... and have been a number of times to their Austin facility to get early info under non-disclosure on their upcoming processors, when they didn't come up to Cambridge to brief the core kernel development team (as did Intel). Cool stuff! |
I'm testing a new decNumber wrapper package - I think I've resolved that problem reasonably cleanly |
@stevengj I'm close to having something showable based on the decNumber library |
Great, thanks for persisting on this! |
@stevengj I've just put a very cringe-worthy attempt at wrapping the decNumber C library up (the very first package I've created, actually!), still very much a work-in-progress, but if you have some time over IAP, I'd love to hear what you think about it. My goal has shifted more from just wrapping it to putting as much of it in Julia as possible, improving the code (it was really written for 32-bit processors, with C compilers that could pass structures), and also getting the arbitrary precision routines to work as well, but still using immutable types for better Julia performance. Needs fleshing out with promotion rules, conversion to/from DecFP BID format from the DPD format, etc. |
FWIW, I've started a pure julia implementation here: https://github.com/quinnj/DecimalNumbers.jl I'm keeping it simple/basic for now, mainly to get stable functionality for database interop. Feel free to try it out and file any issues you see. I'll be switching ODBC over to this new package for 0.6. |
Link to package: https://github.com/quinnj/DecimalNumbers.jl |
Your implementation is not IEEE, but I guess for interop it is not critical to obtain optimal packing or binary compatibility? |
I think having a pure Julia decimal floating point package would be great, but I do think it would be nicer to have it compatible with the IEEE BID format (using half the space for the exponent seems wasteful, IEEE BID gives you 16 digits and a wide exponent range in just 64 bits, as well as support for NaNs and +/-Inf. |
Yes, my two main use-cases are interfacing with databases, as well as a 3rd-party API that provides typed data. Beyond that, only simple calculations are required, so DecimalNumbers.jl should satisfy. |
Will you still have the option for using DecFP for ODBC? That's rather important for us. |
Given that DecFP is not currently useable on 0.6, I'm not planning on supporting it for a 0.6 release. The lack of windows support has also been an on-going inconsistency that DecimalNumbers will resolve. |
The Windows support doesn't affect us (we only deploy on Linux, and do a bit of development on MacOS). I've been so busy getting our product moved to v0.5.1 and finally off of v0.4.7, that I hadn't seen yet that it had problems with v0.6 at the moment. |
(DecFP works in 0.6 now.) |
DecFP is also pretty fast (compare it to BigFloat, for example, it is significantly faster) |
(Windows works now for DecFP. Finally.) |
Has anyone made/seen any recent performance benchmarks (even if not rigorous) between the Intel decimal floating point library and |
|
I'm asking because But I'd like to see some recent comparison. |
@ScottPJones points out that the IBM decNumber package (under the ICU license) may be more portable than the Intel package, and supports more formats. We might consider switching to it, instead of the Intel library.
(A more complex option would be to link to both libraries: using Intel where the performance is better, and decNumber where it supports more functionality.)
Would be interesting to compare the performance of the two libraries.
The text was updated successfully, but these errors were encountered: