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

Hip Refactor #1359

Merged
merged 59 commits into from
May 24, 2024
Merged

Conversation

Bob-Chen222
Copy link
Contributor

@Bob-Chen222 Bob-Chen222 commented Apr 6, 2024

Description of changes:
Hi @lockshaw Colin and @reyna-abhyankar Reyna,
This PR aligned the hip of linear and layer_norm against the Cuda version. If everything works fine, I can proceed to change other hip kernels.

Related Issues:

Linked Issues:

Issues closed by this PR:


This change is Reviewable

@Bob-Chen222 Bob-Chen222 changed the title Bob hip refactor Hip Refactor Apr 7, 2024
Copy link
Collaborator

@reyna-abhyankar reyna-abhyankar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 13 files reviewed, 11 unresolved discussions (waiting on @Bob-Chen222)


docs/doxygen/Doxyfile line 884 at r1 (raw file):

INPUT                 += $(FF_HOME)/python
INPUT                 += $(FF_HOME)/src
INPUT                 += $(FF_HOME)/lib/substitutions/include

What is this change for?


lib/kernels/src/hip/layer_norm_kernels.cpp line 27 at r1 (raw file):

constexpr int kColwiseReduceTileSize = 32;

LayerNormPerDeviceState::LayerNormPerDeviceState(

Actually, you can get rid of this constructor in both the hip and cuda kernels. (Also remove the LayerNormPerDeviceState class, only keep the struct in layer_norm_kernels.h)


lib/kernels/src/hip/layer_norm_kernels.cpp line 57 at r1 (raw file):

                                    int64_t effective_num_elements_,
                                    float eps_) {
  elementwise_affine = elementwise_affine_;

Need to have a datatype for these.

Code snippet:

float* mean = allocator.allocate(...);

lib/kernels/src/hip/layer_norm_kernels.cpp line 67 at r1 (raw file):

  scale = allocator.allocate(sizeof(float) * effective_batch_size);
  bias = allocator.allocate(sizeof(float) * effective_batch_size);
  LayerNormPerDeviceState per_device_state =

Here, just list-initialize LayerNormPerDeviceState (both hip and cuda)

Code snippet:

LayerNormPerDeviceState per_device_state = {handle, elementwise_affine, ...};

lib/kernels/src/hip/layer_norm_kernels.cpp line 85 at r1 (raw file):

struct ForwardKernel {
  void operator()(hipStream_t stream,
                  LayerNormPerDeviceState const *m,

Use reference instead of pointer (same for rest of file)


lib/kernels/src/hip/linear_kernels.cpp line 25 at r1 (raw file):

namespace Linear {

// what's the float * one_ptr

You can get rid of this comment


lib/kernels/src/hip/linear_kernels.cpp line 90 at r1 (raw file):

void forward_kernel(hipStream_t stream,
                    LinearPerDeviceState const *m,

Change to a reference (so use m.xxx instead of m->xxx in the rest of the code)

Code snippet:

LinearPerDeviceState const &m,

lib/kernels/src/hip/linear_kernels.cpp line 152 at r1 (raw file):

                            HIPBLAS_GEMM_DEFAULT));
  }
  if (use_activation(m->activation)) {

use_activation needs to be defined and implemented.

Code snippet:

bool use_activation(ActiMode mode) {
  switch (mode) {
    case AC_MODE_RELU:
    case AC_MODE_SIGMOID:
    case AC_MODE_TANH:
      return true;
    case AC_MODE_NONE:
      return false;
    default:
      assert(0);
      break;
  }
  return false;
}

lib/kernels/src/hip/linear_kernels.cpp line 182 at r1 (raw file):

void backward_kernel(hipStream_t stream,
                     LinearPerDeviceState const *m,

Same here. Use a reference instead of a pointer


lib/substitutions/TUTORIAL.md line 1 at r1 (raw file):

## Tutorial of substitution lib with simple example

Why is this file included?


lib/substitutions/include/substitutions/attribute_expr.h line 10 at r1 (raw file):

enum class ConstraintType { EQUAL };

/**

I'm guessing you may have merged a docs PR with the kernel refactor. We should probably separate these out.

@Bob-Chen222
Copy link
Contributor Author

Hi @reyna-abhyankar, I believe that everything is fixed now! Redundant changes from substitution are eliminated and all the requests you made have been fixed.

Copy link
Contributor Author

@Bob-Chen222 Bob-Chen222 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 16 files reviewed, 11 unresolved discussions (waiting on @reyna-abhyankar)


lib/kernels/src/hip/layer_norm_kernels.cpp line 27 at r1 (raw file):

Previously, reyna-abhyankar (Reyna Abhyankar) wrote…

Actually, you can get rid of this constructor in both the hip and cuda kernels. (Also remove the LayerNormPerDeviceState class, only keep the struct in layer_norm_kernels.h)

Done.


lib/kernels/src/hip/layer_norm_kernels.cpp line 57 at r1 (raw file):

Previously, reyna-abhyankar (Reyna Abhyankar) wrote…

Need to have a datatype for these.

Done.


lib/kernels/src/hip/layer_norm_kernels.cpp line 67 at r1 (raw file):

Previously, reyna-abhyankar (Reyna Abhyankar) wrote…

Here, just list-initialize LayerNormPerDeviceState (both hip and cuda)

Done.


lib/kernels/src/hip/layer_norm_kernels.cpp line 85 at r1 (raw file):

Previously, reyna-abhyankar (Reyna Abhyankar) wrote…

Use reference instead of pointer (same for rest of file)

Done.


lib/kernels/src/hip/linear_kernels.cpp line 25 at r1 (raw file):

Previously, reyna-abhyankar (Reyna Abhyankar) wrote…

You can get rid of this comment

Done.


lib/kernels/src/hip/linear_kernels.cpp line 90 at r1 (raw file):

Previously, reyna-abhyankar (Reyna Abhyankar) wrote…

Change to a reference (so use m.xxx instead of m->xxx in the rest of the code)

Done.


lib/kernels/src/hip/linear_kernels.cpp line 152 at r1 (raw file):

Previously, reyna-abhyankar (Reyna Abhyankar) wrote…

use_activation needs to be defined and implemented.

Done.


lib/kernels/src/hip/linear_kernels.cpp line 182 at r1 (raw file):

Previously, reyna-abhyankar (Reyna Abhyankar) wrote…

Same here. Use a reference instead of a pointer

Done.


docs/doxygen/Doxyfile line 884 at r1 (raw file):

Previously, reyna-abhyankar (Reyna Abhyankar) wrote…

What is this change for?

Done.


lib/substitutions/TUTORIAL.md line 1 at r1 (raw file):

Previously, reyna-abhyankar (Reyna Abhyankar) wrote…

Why is this file included?

Done.


lib/substitutions/include/substitutions/attribute_expr.h line 10 at r1 (raw file):

Previously, reyna-abhyankar (Reyna Abhyankar) wrote…

I'm guessing you may have merged a docs PR with the kernel refactor. We should probably separate these out.

Done.

Copy link
Collaborator

@reyna-abhyankar reyna-abhyankar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: 0 of 16 files reviewed, all discussions resolved

@reyna-abhyankar reyna-abhyankar enabled auto-merge (squash) May 24, 2024 03:05
@reyna-abhyankar reyna-abhyankar merged commit e03b996 into flexflow:repo-refactor May 24, 2024
7 of 8 checks passed
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.

5 participants