herumi / fmath

fast log and exp functions for x86/x64 SSE

Home Page:http://herumi.in.coocan.jp/soft/fmath.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Second argument to expd_v

dabliss opened this issue · comments

I'm getting compiler errors related to calls to expd_v. It's not clear to me what I'm doing wrong, and I'm wondering whether the documentation for exp_v can be improved to prevent people from getting these errors in the future.

Here is the function of mine (get_fourth_term) that uses expd_v:

double get_fourth_term(const std::vector<double> & spike_times, const double t,
                       const double tau, const double tau_1,
                       const double tau_2, const double I_syn_bar,
                       const double C, const double N, const double t_zero)
{

  // Compute values that don't depend on spike_times.
  const double first_other = 1 - exp(t / tau_1 - t / tau);
  const double second_other = 1 - exp(t / tau_2 - t / tau);

  // t is relative to the most recent spike in the network, but spike_times are
  // absolute -- therefore, make them relative to the most recent spike (which
  // occurred at absolute time t_zero).
  const int n_spikes = spike_times.size();
  double first_num[n_spikes];
  double second_num[n_spikes];
  for (int i = 0; i < n_spikes; i += 1)
    {
      first_num[i] = -(t - (spike_times[i] - t_zero)) / tau_1;
      second_num[i] = -(t - (spike_times[i] - t_zero)) / tau_2;
    }

  fmath::expd_v(first_num, sizeof(first_num));
  const double first_denom = 1 / tau - 1 / tau_1;

  fmath::expd_v(second_num, sizeof(second_num));
  const double second_denom = 1 / tau - 1 / tau_2;

  double sum_term = 0;
  for (int i = 0; i < n_spikes; i++)
    {
      const double first_term = first_num[i] / first_denom * first_other;
      const double second_term = second_num[i] / second_denom * second_other;
      sum_term += first_term - second_term;
    }

  return I_syn_bar / (C * N * (tau_1 - tau_2)) * sum_term;

}

These are the compiler errors I get

(master)dbliss@nx3[dopa_net]> g++ -O0 -g hansel.cpp -o hansel.o
In file included from hansel.cpp:7:
fmath.hpp: In member function ‘void fmath::local::ExpCode::makeExp(const fmath::local::ExpVar<N>*, const Xbyak::util::Cpu&) [with long unsigned int N = 10u]’:
fmath.hpp:236:   instantiated from ‘fmath::local::ExpCode::ExpCode(const fmath::local::ExpVar<N>*) [with long unsigned int N = 10u]’
fmath.hpp:389:   instantiated from ‘static const fmath::local::ExpCode& fmath::local::C<EXP_N, LOG_N, EXPD_N>::getInstance() [with long unsigned int EXP_N = 10u, long unsigned int LOG_N = 12u, long unsigned int EXPD_N = 11u]’
fmath.hpp:830:   instantiated from here
fmath.hpp:273: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::a’  of NULL object
fmath.hpp:273: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:281: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::tbl’  of NULL object
fmath.hpp:281: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:283: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::b’  of NULL object
fmath.hpp:283: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:287: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::f1’  of NULL object
fmath.hpp:287: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:296: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::maxX’  of NULL object
fmath.hpp:296: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:297: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::minX’  of NULL object
fmath.hpp:297: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp: In member function ‘void fmath::local::ExpCode::makeExpPs(const fmath::local::ExpVar<N>*, const Xbyak::util::Cpu&) [with long unsigned int N = 10u]’:
fmath.hpp:240:   instantiated from ‘fmath::local::ExpCode::ExpCode(const fmath::local::ExpVar<N>*) [with long unsigned int N = 10u]’
fmath.hpp:389:   instantiated from ‘static const fmath::local::ExpCode& fmath::local::C<EXP_N, LOG_N, EXPD_N>::getInstance() [with long unsigned int EXP_N = 10u, long unsigned int LOG_N = 12u, long unsigned int EXPD_N = 11u]’
fmath.hpp:830:   instantiated from here
fmath.hpp:330: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::i7fffffff’  of NULL object
fmath.hpp:330: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:331: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::a’  of NULL object
fmath.hpp:331: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:332: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::b’  of NULL object
fmath.hpp:332: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:333: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::maxX’  of NULL object
fmath.hpp:333: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:335: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::i127s’  of NULL object
fmath.hpp:335: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:337: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::mask_s’  of NULL object
fmath.hpp:337: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:348: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::tbl’  of NULL object
fmath.hpp:348: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:349: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::f1’  of NULL object
fmath.hpp:349: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:352: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::tbl’  of NULL object
fmath.hpp:352: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:354: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::tbl’  of NULL object
fmath.hpp:354: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:361: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::tbl’  of NULL object
fmath.hpp:361: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:362: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::tbl’  of NULL object
fmath.hpp:362: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:364: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::tbl’  of NULL object
fmath.hpp:364: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:365: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::tbl’  of NULL object
fmath.hpp:365: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:373: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::maxX’  of NULL object
fmath.hpp:373: warning: (perhaps the ‘offsetof’ macro was used incorrectly)
fmath.hpp:374: warning: invalid access to non-static data member ‘fmath::local::ExpVar<10u>::minX’  of NULL object
fmath.hpp:374: warning: (perhaps the ‘offsetof’ macro was used incorrectly)

The second argument of expv_d is the size of array.

double n[1024];
expd_v(n, 1024);
fmath::expd_v(first_num, sizeof(first_num));

The code is wrong. sizeof(first_num) is 4 or 8.
The following code is correct(n_spikes must be multiple of 4 in using AVX2).

fmath::expd_v(first_num, n_spikes);
fmath::expd_v(second_num, n_spikes);

What version of g++?
g++ 4.8.4 and clang++ 3.6 can compile your code.

g++ t.cpp -c -I ../xbyak/ -DFMATH_USE_XBYAK
clang++-3.6 t.cpp -c -I ../xbyak/ -DFMATH_USE_XBYAK -Wno-invalid-offsetof

I'm using g++ version 4.4.7, and I don't have any ability really to change that. I'm on a shared computing cluster.

You say n_spikes must be a multiple of 4. Why is that? For sure the number of spikes (the number of elements in my vector/array) will not always be a multiple of 4. I can't imagine why it would have to be.

Use -Wno-invalid-offsetof if you want to disable warning.

Why is that? For sure the number of spikes (the number of elements in my vector/array) will not always be a multiple of 4. I can't imagine why it would have to be.

expd_v uses AVX/AVX2 and these instructions deal with 2 or 4 double variables, so I omitted remains part.
Now I fix it. Could you try the latest version?

Have you by any chance read this paper? I'd be curious to know whether you benchmarked against that algorithm.

Reading that paper made clearer to me that SIMD architectures can operate on a vector register of four values at once -- I'm guessing this is why you had the requirement of divisibility by four. (For the algorithm in that paper, performance is fine even when the array is not divisible by four -- maybe it's the same for you.)

I will pull and try the latest version now.

OK, so, with the latest update, I don't get any warnings or errors, even without the -Wno-invalid-offsetof flag. Thanks! I'll report back if running the code (now that I've compiled it) raises any errors.

I'm going to close this because we (you, really) have solved the original issue.

I'm getting erroneous results using expd_v when my vector has an odd number of elements and when the elements are smaller than about -90. Right now I'm working to get a better handle on the nature of this bug (if we can call it a bug -- perhaps expd_v is not intended to handle such input). Once I've learned everything I can about it on my end, I'll open a new issue.

I don't the paper. I will read it later.

I don't get any warnings or errors, even without the -Wno-invalid-offsetof flag.

The recent modification of fmath is not for the offsetof, then I don't understand why your warnings are removed.