forked from jax-ml/jax
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[jax_triton] Add user-specified
name
field to serialized format.
PiperOrigin-RevId: 557415723
- Loading branch information
1 parent
c7e8b81
commit 4ac2bdc
Showing
9 changed files
with
126 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "jaxlib/gpu/triton_utils.h" | ||
|
||
#include <zlib.h> | ||
|
||
#include <string> | ||
|
||
#include "absl/status/status.h" | ||
#include "absl/status/statusor.h" | ||
#include "absl/strings/string_view.h" | ||
#include "jaxlib/gpu/gpu_kernel_helpers.h" | ||
#include "jaxlib/gpu/triton.pb.h" | ||
|
||
namespace jax::JAX_GPU_NAMESPACE { | ||
|
||
absl::StatusOr<std::string> ZlibUncompress(absl::string_view compressed) { | ||
std::string data; | ||
uLongf dest_len = 5 * compressed.size(); | ||
while (true) { | ||
data.resize(dest_len); | ||
int ret = uncompress(reinterpret_cast<Bytef*>(data.data()), &dest_len, | ||
reinterpret_cast<const Bytef*>(compressed.data()), | ||
compressed.size()); | ||
if (ret == Z_OK) { | ||
// `uncompress` overwrites `dest_len` with the uncompressed size. | ||
data.resize(dest_len); | ||
break; | ||
} else if (ret == Z_BUF_ERROR) { | ||
dest_len *= 2; // The string buffer wasn't large enough. | ||
} else { | ||
return absl::InvalidArgumentError("Failed to uncompress opaque data."); | ||
} | ||
} | ||
return data; | ||
} | ||
|
||
absl::StatusOr<std::string> GetTritonKernelCallName(absl::string_view opaque) { | ||
JAX_ASSIGN_OR_RETURN(std::string serialized, ZlibUncompress(opaque)); | ||
jax_triton::TritonAnyKernelCall proto; | ||
if (!proto.ParseFromString(serialized)) { | ||
return absl::InvalidArgumentError("Failed to parse serialized data."); | ||
} | ||
return proto.name(); | ||
} | ||
|
||
absl::StatusOr<std::string> GetTritonKernelCallSerializedMetadata( | ||
absl::string_view opaque) { | ||
JAX_ASSIGN_OR_RETURN(std::string serialized, ZlibUncompress(opaque)); | ||
jax_triton::TritonAnyKernelCall proto; | ||
if (!proto.ParseFromString(serialized)) { | ||
return absl::InvalidArgumentError("Failed to parse serialized data."); | ||
} | ||
return proto.metadata(); | ||
} | ||
|
||
} // namespace jax::JAX_GPU_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef JAXLIB_GPU_TRITON_UTILS_H_ | ||
#define JAXLIB_GPU_TRITON_UTILS_H_ | ||
|
||
#include <string> | ||
|
||
#include "absl/status/status.h" | ||
#include "absl/status/statusor.h" | ||
#include "absl/strings/string_view.h" | ||
#include "jaxlib/gpu/vendor.h" | ||
|
||
namespace jax::JAX_GPU_NAMESPACE { | ||
|
||
absl::StatusOr<std::string> ZlibUncompress(absl::string_view compressed); | ||
absl::StatusOr<std::string> GetTritonKernelCallName(absl::string_view opaque); | ||
absl::StatusOr<std::string> GetTritonKernelCallSerializedMetadata( | ||
absl::string_view opaque); | ||
|
||
} // namespace jax::JAX_GPU_NAMESPACE | ||
|
||
#endif // JAXLIB_GPU_TRITON_UTILS_H_ |