Skip to content
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

fuse LARS #4452

Closed
wants to merge 1 commit into from
Closed

fuse LARS #4452

wants to merge 1 commit into from

Conversation

Qazalin
Copy link
Collaborator

@Qazalin Qazalin commented May 6, 2024

631 -> 472 in BACKWARD=1 python3 examples/handcode_resnet50_opt.py
lazy.py allows fusion of assign like:

#include <metal_stdlib>
using namespace metal;
kernel void E_4_4(device float* data0, const device float* data1, const device float* data2, uint3 gid [[threadgroup_position_in_grid]], uint3 lid [[thread_position_in_threadgroup]]) {
  int gidx0 = gid.y; /* 4 */
  int gidx1 = gid.x; /* 4 */
  float val0 = *(data1+gidx0);
  float val1 = *(data2+gidx1);
  *(data0+(gidx0*4)+gidx1) = (val0*val1);
}
#include <metal_stdlib>
using namespace metal;
kernel void E_16n1(device float* data0, const device float* data1, uint3 gid [[threadgroup_position_in_grid]], uint3 lid [[thread_position_in_threadgroup]]) {
  int gidx0 = gid.x; /* 16 */
  float val0 = *(data0+gidx0);
  float val1 = *(data1+gidx0);
  *(data0+gidx0) = ((0.9f*val0)+val1);
}

and this is wrong:

#include <metal_stdlib>
using namespace metal;
kernel void E_4_4n3(device float* data0, const device float* data1, const device float* data2, uint3 gid [[threadgroup_position_in_grid]], uint3 lid [[thread_position_in_threadgroup]]) {
  int gidx0 = gid.y; /* 4 */
  int gidx1 = gid.x; /* 4 */
  int alu0 = ((gidx0*4)+gidx1);
  float val0 = *(data0+alu0);
  float val1 = *(data1+gidx0);
  float val2 = *(data2+gidx1);
  *(data0+alu0) = ((0.9f*val0)+(val1*val2));
}

Copy link
Contributor

github-actions bot commented May 6, 2024

This branch currently is behind tinygrad/master. The line count difference bot is disabled.

@Qazalin Qazalin closed this May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant