Skip to content

Conversation

@ZJUGuoShuai
Copy link
Contributor

This PR aims to implement what #495 needs. I mimic NumPy's numpy.set_printoptions() - it allows users to set a precision. So I added a similar function set_print_precision() into tensor_utils.h.

Example usage:

cudaStream_t stream;
cudaStreamCreate(&stream);

tensor_t<float, 2> x({2, 3});
(x = random<float>({2, 3}, NORMAL)).run(stream);
cudaStreamSynchronize(stream);

printf("x:\n");
print(x);

printf("Current precision: %u.\n", get_print_precision());
set_print_precision(6);
printf("Current precision: %u.\n", get_print_precision());

printf("x:\n");
print(x);

Output:

x:
Tensor{float} Rank: 2, Sizes:[2, 3], Strides:[3,1]
000000: -9.2466e-01 -4.2534e-01 -2.6438e+00 
000001: 1.4518e-01 -1.2087e-01 -5.7973e-01 
Current precision: 4.
Current precision: 6.
x:
Tensor{float} Rank: 2, Sizes:[2, 3], Strides:[3,1]
000000: -9.246624e-01 -4.253442e-01 -2.643846e+00 
000001: 1.451839e-01 -1.208664e-01 -5.797257e-01

@cliffburdick
Copy link
Collaborator

/blossom-ci

@cliffburdick
Copy link
Collaborator

Thanks for the PR @AtomicVar! It looks like it failed the build test:

[ 77%] Linking CUDA executable matx_bench
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_transform/fft.cu.o: in function `matx::set_print_precision(unsigned int)':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: multiple definition of `matx::set_print_precision(unsigned int)'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_transform/fft.cu.o: in function `matx::get_print_precision()':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: multiple definition of `matx::get_print_precision()'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_transform/conv.cu.o: in function `matx::set_print_precision(unsigned int)':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: multiple definition of `matx::set_print_precision(unsigned int)'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_transform/conv.cu.o: in function `matx::get_print_precision()':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: multiple definition of `matx::get_print_precision()'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_transform/cub.cu.o: in function `matx::set_print_precision(unsigned int)':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: multiple definition of `matx::set_print_precision(unsigned int)'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_transform/cub.cu.o: in function `matx::get_print_precision()':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: multiple definition of `matx::get_print_precision()'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_transform/einsum.cu.o: in function `matx::set_print_precision(unsigned int)':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: multiple definition of `matx::set_print_precision(unsigned int)'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_transform/einsum.cu.o: in function `matx::get_print_precision()':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: multiple definition of `matx::get_print_precision()'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_transform/svd_power.cu.o: in function `matx::set_print_precision(unsigned int)':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: multiple definition of `matx::set_print_precision(unsigned int)'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_transform/svd_power.cu.o: in function `matx::get_print_precision()':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: multiple definition of `matx::get_print_precision()'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_transform/qr.cu.o: in function `matx::set_print_precision(unsigned int)':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_desc.h:289: multiple definition of `matx::set_print_precision(unsigned int)'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_transform/qr.cu.o: in function `matx::get_print_precision()':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_desc.h:289: multiple definition of `matx::get_print_precision()'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_operators/operators.cu.o: in function `matx::set_print_precision(unsigned int)':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: multiple definition of `matx::set_print_precision(unsigned int)'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_operators/operators.cu.o: in function `matx::get_print_precision()':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: multiple definition of `matx::get_print_precision()'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_operators/reduction.cu.o: in function `matx::set_print_precision(unsigned int)':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: multiple definition of `matx::set_print_precision(unsigned int)'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/00_operators/reduction.cu.o: in function `matx::get_print_precision()':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: multiple definition of `matx::get_print_precision()'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/01_radar/SingleChanSimplePipeline.cu.o: in function `matx::set_print_precision(unsigned int)':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: multiple definition of `matx::set_print_precision(unsigned int)'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:923: first defined here
/usr/bin/ld: CMakeFiles/matx_bench.dir/01_radar/SingleChanSimplePipeline.cu.o: in function `matx::get_print_precision()':
/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: multiple definition of `matx::get_print_precision()'; CMakeFiles/matx_bench.dir/00_transform/matmul.cu.o:/home/jenkins/workspace/unit-tests/include/matx/core/tensor_utils.h:932: first defined here

My guess is you're missing MATX_INLINE.

@cliffburdick
Copy link
Collaborator

/blossom-ci

@cliffburdick
Copy link
Collaborator

Thanks @AtomicVar !

@cliffburdick cliffburdick merged commit dea0181 into NVIDIA:main Nov 27, 2023
@ZJUGuoShuai ZJUGuoShuai deleted the configurable-precision branch January 16, 2024 04:14
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.

2 participants