Recent

Author Topic: Apple Developer Transition Kit  (Read 31733 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Apple Developer Transition Kit
« Reply #105 on: November 12, 2020, 02:58:42 pm »
On 64-bit Windows it returns "8", which is my 4 physical core + 4 hyperthreading cores.

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Apple Developer Transition Kit
« Reply #106 on: November 12, 2020, 03:12:06 pm »
On 64-bit Windows it returns "8", which is my 4 physical core + 4 hyperthreading cores.

Huh, indeed, on Linux compiling GetCPUCount() with wine fpc.exe and then run the Windows binary with
wine gives "4" as result!

But same code compiled for Linux and run the Linux binary gives "1" as result.

[EDIT]
And with the Linux command:
Code: Bash  [Select][+][-]
  1. $ lscpu

It gives "8" cpu.
« Last Edit: November 12, 2020, 03:22:42 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Apple Developer Transition Kit
« Reply #107 on: November 12, 2020, 05:35:58 pm »
System.GetCPUCount() always returns "1" on Apple Silicon CPU. It should be 4 or maybe 8 cores.
the function doesn't seem to be implemented for Unix systems.

What does processorCount return?

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Apple Developer Transition Kit
« Reply #108 on: November 12, 2020, 06:11:02 pm »
But same code compiled for Linux and run the Linux binary gives "1" as result.
how about this code:
Code: Pascal  [Select][+][-]
  1. uses
  2.   cthreads;
  3.  
  4. function get_nprocs_conf: integer; cdecl; external;
  5.  
  6. function GetCPUCountLinux: Integer;
  7. begin
  8.   Result := get_nprocs_conf;
  9. end;
  10.  
  11. begin
  12.   writeln('proc count: ', GetCPUCountLinux);
  13. end.  
  14.  

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Apple Developer Transition Kit
« Reply #109 on: November 12, 2020, 06:41:52 pm »
another Linux/macOS version:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}
  2.  
  3. uses
  4.   ctypes;
  5.  
  6. const
  7.   // the value changes across Unix OS-es
  8.   _SC_NPROCESSORS_ONLN           = {$ifdef darwin}58{$endif} // macOS
  9.                                    {$else}84{$endif};  // linux
  10.  
  11. function sysconf(conf: cint): clong; cdecl; external;
  12.  
  13. function GetCPUCountUnix: Integer;
  14. begin
  15.   Result := sysconf(_SC_NPROCESSORS_ONLN);
  16. end;
  17.  
  18. begin
  19.   writeln('proc count: ', GetCPUCountUnix);
  20. end.      
  21.  
« Last Edit: November 12, 2020, 06:47:40 pm by skalogryz »

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Apple Developer Transition Kit
« Reply #110 on: November 12, 2020, 09:49:05 pm »
But same code compiled for Linux and run the Linux binary gives "1" as result.
how about this code:
Code: Pascal  [Select][+][-]
  1. uses
  2.   cthreads;
  3.  
  4. function get_nprocs_conf: integer; cdecl; external;
  5.  
  6. function GetCPUCountLinux: Integer;
  7. begin
  8.   Result := get_nprocs_conf;
  9. end;
  10.  
  11. begin
  12.   writeln('proc count: ', GetCPUCountLinux);
  13. end.  
  14.  

Yep, it works:

Code: Bash  [Select][+][-]
  1. ~> ./testcpu
  2. proc count: 8
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Apple Developer Transition Kit
« Reply #111 on: November 12, 2020, 09:58:41 pm »
another Linux/macOS version:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}
  2.  
  3. uses
  4.   ctypes;
  5.  
  6. const
  7.   // the value changes across Unix OS-es
  8.   _SC_NPROCESSORS_ONLN           = {$ifdef darwin}58{$endif} // macOS
  9.                                    {$else}84{$endif};  // linux
  10.  
  11. function sysconf(conf: cint): clong; cdecl; external;
  12.  
  13. function GetCPUCountUnix: Integer;
  14. begin
  15.   Result := sysconf(_SC_NPROCESSORS_ONLN);
  16. end;
  17.  
  18. begin
  19.   writeln('proc count: ', GetCPUCountUnix);
  20. end.      
  21.  

This one gives at compilation:

Quote
Compiling testcpu.pas
Linking testcpu
/usr/bin/ld: testcpu.o: in function `P$TESTCPU_$$_GETCPUCOUNTUNIX$$LONGINT':
testcpu.pas:(.text.n_p$testcpu_$$_getcpucountunix$$longint+0x11): undefined reference to `sysconf'
testcpu.pas(22,5) Error: Error while linking
testcpu.pas(22,5) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted


I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Apple Developer Transition Kit
« Reply #112 on: November 12, 2020, 10:40:40 pm »
please add cthreads to the uses clause. This should link the required library

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Apple Developer Transition Kit
« Reply #113 on: November 12, 2020, 10:44:13 pm »
please add cthreads to the uses clause. This should link the required library

Ha, ok, now it compiles ok and the result is ok too.
Code: Pascal  [Select][+][-]
  1. ~> ./testcpu
  2. proc count: 8
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: Apple Developer Transition Kit
« Reply #114 on: November 13, 2020, 03:32:46 pm »
skalogryz,

Thanks for your reply!

Your code works fine on both Macs - Intel and Apple DTK:

DTK returns "8" cores.

Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}
  2.  
  3. uses
  4.   ctypes, cthreads;
  5.  
  6. const
  7.   // the value changes across Unix OS-es
  8.   _SC_NPROCESSORS_ONLN           = {$ifdef darwin}58{$endif} // macOS
  9.                                    {$else}84{$endif};  // linux
  10.  
  11. function sysconf(conf: cint): clong; cdecl; external;
  12.  
  13. function GetCPUCountUnix: Integer;
  14. begin
  15.   Result := sysconf(_SC_NPROCESSORS_ONLN);
  16. end;
  17.  
  18. begin
  19.   writeln('proc count: ', GetCPUCountUnix);
  20. end.

Another variant doesn't link on Apple DTK for aarch64:

Code: Pascal  [Select][+][-]
  1. uses
  2.   cthreads;
  3.  
  4. function get_nprocs_conf: integer; cdecl; external;
  5.  
  6. function GetCPUCountLinux: Integer;
  7. begin
  8.   Result := get_nprocs_conf;
  9. end;
  10.  
  11. begin
  12.   writeln('proc count: ', GetCPUCountLinux);
  13. end.  

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Apple Developer Transition Kit
« Reply #115 on: November 13, 2020, 03:42:46 pm »
What value does the number of logical cores _alone_ have? It is only useful if you also have the physical cores. (e.g. if you have 6 real cores + HT, then start 8 threads. But starting twelve is nearly always overkill)

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: Apple Developer Transition Kit
« Reply #116 on: November 13, 2020, 03:49:36 pm »
Apple DTK has 8 cores (4 high-speed and 4 energy saving).

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Apple Developer Transition Kit
« Reply #117 on: November 13, 2020, 04:02:54 pm »
Another variant doesn't link on Apple DTK for aarch64:
it should not link on macOS. get_nprocs_conf() is a Linux specific function.

What about processorCount?

The code might look like thise
Code: Pascal  [Select][+][-]
  1. uses
  2.   CocoaAll;
  3. {$modeswitch objectiveC2}
  4.  
  5. begin
  6.   writeln('proc count: ', NSProcessInfo processInfo.processorCount);
  7. end.  

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Apple Developer Transition Kit
« Reply #118 on: November 13, 2020, 06:40:34 pm »
Apple DTK has 8 cores (4 high-speed and 4 energy saving).

Can they all work in parallel? If not, than that is the a different setup, but the same problem.

IOW what good does the figure "8" for cores if only 4 can work at any one given time?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Re: Apple Developer Transition Kit
« Reply #119 on: November 13, 2020, 08:48:51 pm »
Apple DTK has 8 cores (4 high-speed and 4 energy saving).

Can they all work in parallel?
Yes.

 

TinyPortal © 2005-2018