forked from flang-compiler/flang
-
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.
Fix for random_seed when seeds have zeroes in LSB
This patch fixes setting random seeds when seeds are large and has zeroes in their least significant 23 bits. Fixes flang-compiler#691 Change-Id: If532da3159997a4ddbecd20f388a5e6280bc1012
- Loading branch information
1 parent
2800441
commit 0dbe81d
Showing
7 changed files
with
294 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
EXE=random_seed_fix.$(EXESUFFIX) | ||
|
||
build: $(SRC)/random_seed_fix.f90 | ||
-$(RM) random_seed_fix.$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.* | ||
-$(RM) $(OBJ) | ||
-$(CC) -c $(CFLAGS) $(SRC)/check.c -o check.$(OBJX) | ||
@echo ------------------------------------ building test $@ | ||
$(FC) $(FFLAGS) $(LDFLAGS) $(SRC)/random_seed_fix.f90 check.$(OBJX) -o random_seed_fix.$(EXESUFFIX) | ||
|
||
run: | ||
@echo ------------------------------------ executing test random_seed_fix | ||
random_seed_fix.$(EXESUFFIX) | ||
|
||
verify: ; | ||
|
||
random_seed_fix.run: run |
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,32 @@ | ||
# | ||
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
EXE=random_seed_i8_fix.$(EXESUFFIX) | ||
|
||
build: $(SRC)/random_seed_i8_fix.f90 | ||
-$(RM) random_seed_i8_fix.$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.* | ||
-$(RM) $(OBJ) | ||
-$(CC) -c $(CFLAGS) $(SRC)/check.c -o check.$(OBJX) | ||
@echo ------------------------------------ building test $@ | ||
$(FC) $(FFLAGS) -i8 $(LDFLAGS) $(SRC)/random_seed_i8_fix.f90 check.$(OBJX) -o random_seed_i8_fix.$(EXESUFFIX) | ||
|
||
run: | ||
@echo ------------------------------------ executing test random_seed_i8_fix | ||
random_seed_i8_fix.$(EXESUFFIX) | ||
|
||
verify: ; | ||
|
||
random_seed_i8_fix.run: run |
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 @@ | ||
# | ||
# Copyright (c) 2019, Arm Ltd. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Shared lit script for each tests. Run bash commands that run tests with make. | ||
# This test is expected to fail till PGI switches the allocatable default to 03 | ||
|
||
# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t | ||
# RUN: cat %t | FileCheck %S/runmake |
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 @@ | ||
# | ||
# Copyright (c) 2019, Arm Ltd. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Shared lit script for each tests. Run bash commands that run tests with make. | ||
# This test is expected to fail till PGI switches the allocatable default to 03 | ||
|
||
# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t | ||
# RUN: cat %t | FileCheck %S/runmake |
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,68 @@ | ||
!** Copyright (c) 2019, Arm Ltd. All rights reserved. | ||
|
||
!** Licensed under the Apache License, Version 2.0 (the "License"); | ||
!** you may not use this file except in compliance with the License. | ||
!** You may obtain a copy of the License at | ||
!** | ||
!** http://www.apache.org/licenses/LICENSE-2.0 | ||
!** | ||
!** Unless required by applicable law or agreed to in writing, software | ||
!** distributed under the License is distributed on an "AS IS" BASIS, | ||
!** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
!** See the License for the specific language governing permissions and | ||
!** limitations under the License. | ||
|
||
!* Test random_seed fix | ||
program test | ||
integer, parameter :: num = 1 | ||
integer rslts(num), expect(num) | ||
data expect / 1 / | ||
|
||
call test_with_sized_seed_array() | ||
call test_with_large_seed_array() | ||
call test_with_small_seed_array() | ||
|
||
rslts(1) = 1 | ||
call check(rslts, expect, num) | ||
contains | ||
subroutine test_with_sized_seed_array() | ||
integer :: my_seed_sz | ||
integer, allocatable :: my_seed_arr(:) | ||
real :: my_rand | ||
|
||
call random_seed(size=my_seed_sz) | ||
|
||
allocate(my_seed_arr(my_seed_sz)) | ||
my_seed_arr = 0 | ||
my_seed_arr(1) = Z'800000' | ||
|
||
call random_seed(put=my_seed_arr) | ||
call random_number(my_rand) | ||
|
||
deallocate(my_seed_arr) | ||
end subroutine | ||
|
||
subroutine test_with_small_seed_array() | ||
integer, parameter :: my_seed_sz=8 | ||
integer :: my_seed_arr(my_seed_sz) | ||
real :: my_rand | ||
|
||
my_seed_arr = 0 | ||
my_seed_arr(1) = Z'800000' | ||
|
||
call random_seed(put=my_seed_arr) | ||
call random_number(my_rand) | ||
end subroutine | ||
|
||
subroutine test_with_large_seed_array() | ||
integer, parameter :: my_seed_sz=51 | ||
integer :: my_seed_arr(my_seed_sz) | ||
real :: my_rand | ||
|
||
my_seed_arr = 0 | ||
my_seed_arr(1) = Z'800000' | ||
|
||
call random_seed(put=my_seed_arr) | ||
call random_number(my_rand) | ||
end subroutine | ||
end program |
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,68 @@ | ||
!** Copyright (c) 2019, Arm Ltd. All rights reserved. | ||
|
||
!** Licensed under the Apache License, Version 2.0 (the "License"); | ||
!** you may not use this file except in compliance with the License. | ||
!** You may obtain a copy of the License at | ||
!** | ||
!** http://www.apache.org/licenses/LICENSE-2.0 | ||
!** | ||
!** Unless required by applicable law or agreed to in writing, software | ||
!** distributed under the License is distributed on an "AS IS" BASIS, | ||
!** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
!** See the License for the specific language governing permissions and | ||
!** limitations under the License. | ||
|
||
!* Test random_seed fix | ||
program test | ||
integer, parameter :: num = 1 | ||
integer rslts(num), expect(num) | ||
data expect / 1 / | ||
|
||
call test_with_sized_seed_array() | ||
call test_with_large_seed_array() | ||
call test_with_small_seed_array() | ||
|
||
rslts(1) = 1 | ||
call check(rslts, expect, num) | ||
contains | ||
subroutine test_with_sized_seed_array() | ||
integer :: my_seed_sz | ||
integer, allocatable :: my_seed_arr(:) | ||
real :: my_rand | ||
|
||
call random_seed(size=my_seed_sz) | ||
|
||
allocate(my_seed_arr(my_seed_sz)) | ||
my_seed_arr = 0 | ||
my_seed_arr(1) = Z'800000000000000' | ||
|
||
call random_seed(put=my_seed_arr) | ||
call random_number(my_rand) | ||
|
||
deallocate(my_seed_arr) | ||
end subroutine | ||
|
||
subroutine test_with_small_seed_array() | ||
integer, parameter :: my_seed_sz=8 | ||
integer :: my_seed_arr(my_seed_sz) | ||
real :: my_rand | ||
|
||
my_seed_arr = 0 | ||
my_seed_arr(1) = Z'800000000000000' | ||
|
||
call random_seed(put=my_seed_arr) | ||
call random_number(my_rand) | ||
end subroutine | ||
|
||
subroutine test_with_large_seed_array() | ||
integer, parameter :: my_seed_sz=51 | ||
integer :: my_seed_arr(my_seed_sz) | ||
real :: my_rand | ||
|
||
my_seed_arr = 0 | ||
my_seed_arr(1) = Z'800000000000000' | ||
|
||
call random_seed(put=my_seed_arr) | ||
call random_number(my_rand) | ||
end subroutine | ||
end program |