-
Notifications
You must be signed in to change notification settings - Fork 206
add 2 kernel metrics #185
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
Closed
Closed
add 2 kernel metrics #185
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,73 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* All rights reserved. | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "CudaDeviceProperties.h" | ||
|
||
#include <vector> | ||
|
||
#include <cuda_runtime.h> | ||
#include <cuda_occupancy.h> | ||
|
||
namespace KINETO_NAMESPACE { | ||
|
||
std::vector<cudaOccDeviceProp> createOccDeviceProps() { | ||
std::vector<cudaOccDeviceProp> occProps; | ||
int device_count; | ||
cudaError_t error_id = cudaGetDeviceCount(&device_count); | ||
// Return empty vector if error. | ||
if (error_id != cudaSuccess) { | ||
return occProps; | ||
} | ||
for (int i = 0; i < device_count; ++i) { | ||
cudaDeviceProp prop; | ||
error_id = cudaGetDeviceProperties(&prop, i); | ||
// Return empty vector if any device property fail to get. | ||
if (error_id != cudaSuccess) { | ||
return occProps; | ||
} | ||
cudaOccDeviceProp occProp; | ||
occProp = prop; | ||
occProps.push_back(occProp); | ||
} | ||
return occProps; | ||
} | ||
|
||
const std::vector<cudaOccDeviceProp>& occDeviceProps() { | ||
static std::vector<cudaOccDeviceProp> occProps = createOccDeviceProps(); | ||
return occProps; | ||
} | ||
|
||
float getKernelOccupancy(uint32_t deviceId, uint16_t registersPerThread, | ||
int32_t staticSharedMemory, int32_t dynamicSharedMemory, | ||
int32_t blockX, int32_t blockY, int32_t blockZ) { | ||
// Calculate occupancy | ||
float occupancy = -1.0; | ||
const std::vector<cudaOccDeviceProp> &occProps = occDeviceProps(); | ||
if (deviceId < occProps.size()) { | ||
cudaOccFuncAttributes occFuncAttr; | ||
occFuncAttr.maxThreadsPerBlock = INT_MAX; | ||
occFuncAttr.numRegs = registersPerThread; | ||
occFuncAttr.sharedSizeBytes = staticSharedMemory; | ||
occFuncAttr.partitionedGCConfig = PARTITIONED_GC_OFF; | ||
occFuncAttr.shmemLimitConfig = FUNC_SHMEM_LIMIT_DEFAULT; | ||
occFuncAttr.maxDynamicSharedSizeBytes = 0; | ||
const cudaOccDeviceState occDeviceState = {}; | ||
int blockSize = blockX * blockY * blockZ; | ||
size_t dynamicSmemSize = dynamicSharedMemory; | ||
cudaOccResult occ_result; | ||
cudaOccError status = cudaOccMaxActiveBlocksPerMultiprocessor( | ||
&occ_result, &occProps[deviceId], &occFuncAttr, &occDeviceState, | ||
blockSize, dynamicSmemSize); | ||
if (status == CUDA_OCC_SUCCESS) { | ||
occupancy = occ_result.activeBlocksPerMultiprocessor * blockSize / | ||
(float) occProps[deviceId].maxThreadsPerMultiprocessor; | ||
} | ||
} | ||
return occupancy; | ||
} | ||
|
||
} // namespace KINETO_NAMESPACE |
This file contains hidden or 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,18 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* All rights reserved. | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
namespace KINETO_NAMESPACE { | ||
|
||
float getKernelOccupancy(uint32_t deviceId, uint16_t registersPerThread, | ||
int32_t staticSharedMemory, int32_t dynamicSharedMemory, | ||
int32_t blockX, int32_t blockY, int32_t blockZ); | ||
|
||
} // namespace KINETO_NAMESPACE |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me check whether we add a different copyright header...